Re: passing values to a function

From: Jan Wieck <janwieck(at)Yahoo(dot)com>
To: Cedar Cox <cedarc(at)visionforisrael(dot)com>
Cc: pgsql-interfaces(at)postgresql(dot)org
Subject: Re: passing values to a function
Date: 2001-02-19 19:32:09
Message-ID: 200102191932.OAA01894@jupiter.jw.home
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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(at)Yahoo(dot)com #

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

In response to

Responses

Browse pgsql-interfaces by date

  From Date Subject
Next Message Adam Haberlach 2001-02-19 20:07:31 First-time JDBC setup with Jakarta! Whee!
Previous Message Alexaki Sofia 2001-02-19 15:35:17 COPY and UNICODE encoding