Re: %ROWTYPE as PL/pgsql argument

Поиск
Список
Период
Сортировка
От Richard Emberson
Тема Re: %ROWTYPE as PL/pgsql argument
Дата
Msg-id 3CA9E238.B297E73@phc.net
обсуждение исходный текст
Ответ на Re: %ROWTYPE as PL/pgsql argument  (Jan Wieck <janwieck@yahoo.com>)
Список 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 по дате отправления:

Предыдущее
От: James Leigh
Дата:
Сообщение: dropping large objects
Следующее
От: Richard Emberson
Дата:
Сообщение: Re: v7.2.1 Released: Critical Bug Fix