Re: %ROWTYPE as PL/pgsql argument - Mailing list pgsql-general

From Richard Emberson
Subject Re: %ROWTYPE as PL/pgsql argument
Date
Msg-id 3CA9E238.B297E73@phc.net
Whole thread Raw
In response to Re: %ROWTYPE as PL/pgsql argument  (Jan Wieck <janwieck@yahoo.com>)
List pgsql-general
Tom Lane wrote:

> Jan Wieck <janwieck@yahoo.com> writes:
> >     At  the  time  beeing  you  can't  do that with PL/pgSQL. The
> >     language can receive rows as parameters, but it cannot  build
> >     those rows and pass them down to called functions.
>
> Hmm, doesn't it work to do
>
>         declare var some-row-type;
>
>         select x, y, z into var;
>
>         select otherfunc(var);
>
>                         regards, tom lane

I tried it and it did not work. It gave an error message something like
"var attribute not found" at the point in the procedure where the
otherfunc was called.

In the following it died at the line:
RETURN xy(type_row_v);

(by the way, if you change the line:
    type_row_v type%ROWTYPE;
to
    type_row_v type;
the connection with the backend is cut.)


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


pgsql-general by date:

Previous
From: James Leigh
Date:
Subject: dropping large objects
Next
From: Richard Emberson
Date:
Subject: Re: v7.2.1 Released: Critical Bug Fix