Re: passing values to a function - Mailing list pgsql-interfaces

From Jan Wieck
Subject Re: passing values to a function
Date
Msg-id 200102191932.OAA01894@jupiter.jw.home
Whole thread Raw
In response to passing values to a function  (Cedar Cox <cedarc@visionforisrael.com>)
Responses Re: passing values to a function
List pgsql-interfaces
Cedar Cox wrote:
>
> Why does this not work?  Am I doing something wrong?
>
> CREATE FUNCTION uutest(text) RETURNS bool AS '
> declare
>   varop alias for $1;
> begin
>   raise notice '' varop is '',varop;
   raise notice '' varop is %'', varop;

>   return false;
> end;
> ' LANGUAGE 'plpgsql';
> [...]
>
> One other question.. Is there an easy way to pass an entire record to a
> function (eg, the 'new' record)?  Presently I am passing all 12 fields as
> separate parameters.
   Yes and no.
   Yes,  PL/pgSQL functions can receive tuples as arguments. The   only oddity is that they *must* get  aliased  for
access of   attributes. Your function would look like:
 
       CREATE FUNCTION myfunc (mytable) RETURNS text AS '       DECLARE           row ALIAS FOR %1;       BEGIN
 return row.key || '' equals '' row.value;       END;'       LANGUAGE 'plpgsql';
 
   But unfortunately (and there's no really good reason why) no,   a PL/pgSQL function  having  some  row  somehow
cannot call   another  function  handing that row over as a tuple argument.   Something to work on for 7.2.
 


Jan

--

#======================================================================#
# It's easier to get forgiveness for being wrong than for being right. #
# Let's break this rule - forgive me.                                  #
#================================================== JanWieck@Yahoo.com #



_________________________________________________________
Do You Yahoo!?
Get your free @yahoo.com address at http://mail.yahoo.com



pgsql-interfaces by date:

Previous
From: Adam Haberlach
Date:
Subject: First-time JDBC setup with Jakarta! Whee!
Next
From: Cedar Cox
Date:
Subject: Re: passing values to a function