Re: %ROWTYPE as PL/pgsql argument
От | Jan Wieck |
---|---|
Тема | Re: %ROWTYPE as PL/pgsql argument |
Дата | |
Msg-id | 200204021421.g32EL4J30767@saturn.janwieck.net обсуждение исходный текст |
Ответ на | Re: %ROWTYPE as PL/pgsql argument (Richard Emberson <emberson@phc.net>) |
Ответы |
Re: %ROWTYPE as PL/pgsql argument
|
Список | pgsql-general |
Richard Emberson wrote: > 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 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. Jan > > > 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 > > > ---------------------------(end of broadcast)--------------------------- > TIP 3: if posting/reading through Usenet, please send an appropriate > subscribe-nomail command to majordomo@postgresql.org so that your > message can get through to the mailing list cleanly > -- #======================================================================# # It's easier to get forgiveness for being wrong than for being right. # # Let's break this rule - forgive me. # #================================================== JanWieck@Yahoo.com # _________________________________________________________ Do You Yahoo!? Get your free @yahoo.com address at http://mail.yahoo.com
В списке pgsql-general по дате отправления: