Re: %ROWTYPE as PL/pgsql argument
От | Richard Emberson |
---|---|
Тема | Re: %ROWTYPE as PL/pgsql argument |
Дата | |
Msg-id | 3CA91EB5.325308EC@phc.net обсуждение исходный текст |
Ответ на | %ROWTYPE as PL/pgsql argument (Richard Emberson <emberson@phc.net>) |
Ответы |
Re: %ROWTYPE as PL/pgsql argument
|
Список | 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 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
В списке pgsql-general по дате отправления: