niXforums Forum Index
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   PreferencesPreferences   Log in to check your private messagesLog in to check your private messages   Log inLog in 
·  nixdoc.net ·  man pages ·  Linux HOWTOs ·  FreeBSD Tips ·  Forums
navigation Forum index » Databases » PostgreSQL
plPerl subroutine
Post new topic   Reply to topic Page 1 of 1 [4 Posts] View previous topic :: View next topic
Author Message
FERREIRA William (COFRAMI
*nix forums beginner


Joined: 07 Mar 2005
Posts: 34

PostPosted: Wed Mar 16, 2005 1:17 pm    Post subject: plPerl subroutine Reply with quote

hi

is it possible to create subroutines with plPerl ?

i tried this :
CREATE OR REPLACE FUNCTION adoc.CREATE_XML_FILE(docId int4, eleId int4, evo
int4, fileName text, fileRelativeDir text)
RETURNS int4 AS
$BODY$
my $theClob='';

my $params = 'select
adoc.GET_XML_FRAG('.$_[0].','.$_[1].','.$_[2].',\''.$theClob.'\','.0;
$params = $params.')';

$theClob = spi_exec_query($params);
elog NOTICE, $theClob;

return 4;
$BODY$
LANGUAGE 'plperl' VOLATILE;

CREATE OR REPLACE FUNCTION adoc.GET_XML_FRAG(docId int4, eleId int4, evo
int4, clob text, indx int4)
RETURNS text AS
$BODY$
my $t_clob = $_[3].'totototototototototot';

return $t_clob;
$BODY$
LANGUAGE 'plperl' VOLATILE;

but the CREATE_XML_FILE doesn't display 'totototototototototot' but
HASH(0xf03fa4)....

is it possible with this solution or does i need to create a module
(including makefile, .pm, ...) ?
if i must create a module, can you explain how to do ?

thanks
Back to top
Sean Davis
*nix forums Guru Wannabe


Joined: 01 Mar 2005
Posts: 172

PostPosted: Wed Mar 16, 2005 2:09 pm    Post subject: Re: plPerl subroutine Reply with quote

My understanding is that pl/perl functions are simply anonymous
coderefs, so they can't call each other. What is it that you REALLY
want to do? (The code looks a bit like a toy example.)

Sean

On Mar 16, 2005, at 9:17 AM, FERREIRA William (COFRAMI) wrote:

Quote:
hi
 
is it possible to create subroutines with plPerl ?
 
i tried this :
CREATE OR REPLACE FUNCTION adoc.CREATE_XML_FILE(docId int4, eleId
int4, evo int4, fileName text, fileRelativeDir text)
  RETURNS int4 AS
$BODY$
 my $theClob='';
 
 my $params = 'select
adoc.GET_XML_FRAG('.$_[0].','.$_[1].','.$_[2].',\''.$theClob.'\','.0;
 $params = $params.')';
 
 $theClob =  spi_exec_query($params);
 elog NOTICE, $theClob;
 
 return 4;
$BODY$
  LANGUAGE 'plperl' VOLATILE;
 
CREATE OR REPLACE FUNCTION adoc.GET_XML_FRAG(docId int4, eleId int4,
evo int4, clob text, indx int4)
  RETURNS text AS
$BODY$
 my $t_clob = $_[3].'totototototototototot';
 
 return $t_clob;
$BODY$
  LANGUAGE 'plperl' VOLATILE;
but the CREATE_XML_FILE doesn't display 'totototototototototot' but
HASH(0xf03fa4)....
 
is it possible with this solution or does i need to create a module
(including makefile, .pm, ...) ?
if i must create a module, can you explain how to do ?
 

thanks


---------------------------(end of broadcast)---------------------------
TIP 3: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to majordomo@postgresql.org so that your
message can get through to the mailing list cleanly
Back to top
Tom Lane
*nix forums Guru


Joined: 24 Mar 2005
Posts: 2070

PostPosted: Wed Mar 16, 2005 2:33 pm    Post subject: Re: plPerl subroutine Reply with quote

"FERREIRA William (COFRAMI)" <william.ferreira@airbus.com> writes:
Quote:
but the CREATE_XML_FILE doesn't display 'totototototototototot' but
HASH(0xf03fa4)....

I think what you get back from spi_exec_query is always going to be
a hash, even if it contains only one field. So you need to pick out
the field value.

regards, tom lane

---------------------------(end of broadcast)---------------------------
TIP 2: you can get off all lists at once with the unregister command
(send "unregister YourEmailAddressHere" to majordomo@postgresql.org)
Back to top
Harald Fuchs
*nix forums addict


Joined: 14 Mar 2005
Posts: 73

PostPosted: Wed Mar 16, 2005 2:37 pm    Post subject: Re: plPerl subroutine Reply with quote

In article <1904E3EB39448246A7ECB76DF34A70B00143B48A@TOCOMEXC03>,
"FERREIRA William (COFRAMI)" <william.ferreira@airbus.com> writes:
Quote:
CREATE OR REPLACE FUNCTION adoc.CREATE_XML_FILE(docId int4, eleId int4, evo
int4, fileName text, fileRelativeDir text)
  RETURNS int4 AS
$BODY$
 my $theClob='';
 
 my $params = 'select
adoc.GET_XML_FRAG('.$_[0].','.$_[1].','.$_[2].',\''.$theClob.'\','.0;
 $params = $params.')';

 

 $theClob =  spi_exec_query($params);

 elog NOTICE, $theClob;

 

 return 4;
$BODY$
  LANGUAGE 'plperl' VOLATILE;

 

CREATE OR REPLACE FUNCTION adoc.GET_XML_FRAG(docId int4, eleId int4, evo int4,
clob text, indx int4)
  RETURNS text AS
$BODY$
 my $t_clob = $_[3].'totototototototototot';
 
 return $t_clob;
$BODY$
  LANGUAGE 'plperl' VOLATILE;

but the CREATE_XML_FILE doesn't display 'totototototototototot' but
HASH(0xf03fa4)....


.... and rightly so. As documented in The Fine Manual, spi_exec_query
returns a hash reference. Probably you want something like

my $rv = spi_exec_query($params);
$theClob = $rv-.{rows}[0]->{get_xml_frag};


---------------------------(end of broadcast)---------------------------
TIP 3: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to majordomo@postgresql.org so that your
message can get through to the mailing list cleanly
Back to top
Google

Back to top
Display posts from previous:   
Post new topic   Reply to topic Page 1 of 1 [4 Posts] View previous topic :: View next topic
The time now is Fri Jan 09, 2009 6:53 am | All times are GMT
navigation Forum index » Databases » PostgreSQL
Jump to:  

Similar Topics
Topic Author Forum Replies Last Post
No new posts subroutine weberw@adelphia.net Perl 6 Thu Jul 20, 2006 9:36 pm
No new posts FAQ 4.67 Why does passing a subroutine an undefined eleme... PerlFAQ Server Perl 0 Sun Jul 02, 2006 7:03 am
No new posts Dynamic technical graphics generation inside plperl query? Philippe Lang PostgreSQL 1 Sat Jul 01, 2006 10:49 am
No new posts How to pass an array and scalar as arguments to a subrout... TheOrangeRemix Perl 5 Wed Jun 28, 2006 4:16 pm
No new posts Plperl and my() lexical variables bug? Philippe Lang PostgreSQL 2 Fri Jun 23, 2006 9:33 am

Online Advertising | Notebook Deals | Credit Cards UK | Credit Counseling | Credit Cards
Copyright © 2004-2005 DeniX Solutions SRL
 
Other DeniX Solutions sites: Unix/Linux blog |  electronics forum |  medicine forum |  science forum | 
Privacy Policy


Powered by phpBB © 2001, 2005 phpBB Group
[ Time: 0.1661s ][ Queries: 16 (0.0784s) ][ GZIP on - Debug on ]