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: Jan Wieck <janwieck(at)yahoo(dot)com>, pgsql-general(at)postgresql(dot)org
Subject: Re: %ROWTYPE as PL/pgsql argument
Date: 2002-04-02 16:54:16
Message-ID: 3CA9E238.B297E73@phc.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Tom Lane wrote:

> Jan Wieck <janwieck(at)yahoo(dot)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

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Richard Emberson 2002-04-02 17:00:11 Re: v7.2.1 Released: Critical Bug Fix
Previous Message James Leigh 2002-04-02 16:46:59 dropping large objects