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