Re: %ROWTYPE as PL/pgsql argument

From: Richard Emberson <emberson(at)phc(dot)net>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: %ROWTYPE as PL/pgsql argument
Date: 2002-04-02 03:00:05
Message-ID: 3CA91EB5.325308EC@phc.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Tom Lane wrote:

> Richard Emberson <emberson(at)phc(dot)net> writes:
> > CREATE OR REPLACE FUNCTION testFunc(mytable%ROWTYPE)
>
> There's no %ROWTYPE in Postgres SQL. There's no need for it, because
> the table name is also the name of the rowtype datatype --- so you
> should have written just
>
> CREATE OR REPLACE FUNCTION testFunc(mytable)
>
> regards, tom lane

If I try the following, I get the error:
=> select x(1);
NOTICE: Error occurred while executing PL/pgSQL function x
NOTICE: line 9 at return
ERROR: Attribute 'type_row_v' not found

So how do I generate a row that can be used as a parameter to a
function?
thanks

CREATE OR REPLACE FUNCTION x(
BIGINT
)
RETURNS BIGINT AS '
DECLARE
type_id_p ALIAS FOR $1;
type_row_v type%ROWTYPE;
BEGIN
SELECT * INTO type_row_v FROM type
WHERE type_id = type_id_p;

RETURN xy(type_row_v);
END;
' LANGUAGE 'plpgsql' WITH (isstrict);

CREATE OR REPLACE FUNCTION xy(
type
)
RETURNS BIGINT AS '
DECLARE
type_row_p ALIAS FOR $1;
BEGIN

IF type_row_p.type_id IS NULL THEN
RETURN -2;
END IF;

RETURN type_row_p.type_kind;
END;
' LANGUAGE 'plpgsql' WITH (isstrict);

Richard

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Richard Emberson 2002-04-02 03:02:55 Re: %ROWTYPE as PL/pgsql argument
Previous Message Paul M Foster 2002-04-02 02:18:24 Return value if table doesn't exist