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

From Richard Emberson
Subject Re: %ROWTYPE as PL/pgsql argument
Date
Msg-id 3CA91F5F.3231F6B9@phc.net
Whole thread Raw
In response to %ROWTYPE as PL/pgsql argument  (Richard Emberson <emberson@phc.net>)
List pgsql-general
Tom Lane wrote:

> Richard Emberson <emberson@phc.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

The following does work ... (does the refcursor get closed automatically
in this example?)


CREATE OR REPLACE FUNCTION x(
BIGINT
)
RETURNS BIGINT AS '
DECLARE
    type_id_p ALIAS FOR $1;
    type_rc_v REFCURSOR;
BEGIN
    OPEN type_rc_v FOR SELECT * FROM type
        WHERE type_id = type_id_p;

    RETURN xxx(type_rc_v);
END;
' LANGUAGE 'plpgsql' WITH (isstrict);

CREATE OR REPLACE FUNCTION xxx(
REFCURSOR
)
RETURNS BIGINT AS '
DECLARE
    type_rc_p ALIAS FOR $1;
    type_row_v type%ROWTYPE;
BEGIN
    FETCH type_rc_p INTO type_row_v;

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

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



pgsql-general by date:

Previous
From: Richard Emberson
Date:
Subject: Re: %ROWTYPE as PL/pgsql argument
Next
From: "Dominic J. Eidson"
Date:
Subject: Errors when running vacuumdb...