Re: Rowtype or Record parameters to pl/pgsql functions

From: Joe Conway <mail(at)joeconway(dot)com>
To: Diana Duncan <dianaduncan(at)nc(dot)rr(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Rowtype or Record parameters to pl/pgsql functions
Date: 2003-06-08 22:20:56
Message-ID: 3EE3B6C8.2050708@joeconway.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Diana Duncan wrote:
> CREATE FUNCTION "insert_history" (ip_resources_current%rowtype,
> interval) RETURNS integer AS '
> declare
> v_currentRec alias for $1;
> ...
>
> I get an error upon creation - ERROR: parser: parse error at or near
> "%" at character 54
>
> When I replace the %rowtype with the datatype record, the function is
> created all right, but when it is called from another function with a
> rowtype or a record variable named xrefrec, I get a runtime error -
> ERROR: Attribute "xrefrec" not found

Just specifiy the type name (e.g. ip_resources_current) without the
%rowtype. For example:

CREATE TABLE foo (f1 int, f2 text);
INSERT INTO foo VALUES (1,'a');
CREATE OR REPLACE FUNCTION func1(foo) RETURNS text AS 'SELECT $1.f2'
LANGUAGE 'sql';
CREATE OR REPLACE FUNCTION func2(int) RETURNS foo AS 'SELECT * FROM foo
WHERE f1 = $1' LANGUAGE 'sql';
regression=# SELECT func1(func2(1));
func1
-------
a
(1 row)

HTH,

Joe

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Alvaro Herrera 2003-06-09 01:28:29 Re: Linux 2.6 kernel,
Previous Message Avi Schwartz 2003-06-08 21:27:59 Re: Temporary tables inside functions problem