Re: %ROWTYPE as PL/pgsql argument

From: Jan Wieck <janwieck(at)yahoo(dot)com>
To: Richard Emberson <emberson(at)phc(dot)net>
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, pgsql-general(at)postgresql(dot)org
Subject: Re: %ROWTYPE as PL/pgsql argument
Date: 2002-04-02 14:21:04
Message-ID: 200204021421.g32EL4J30767@saturn.janwieck.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Richard Emberson wrote:
> Tom Lane wrote:
>
> > Richard Emberson <emberson(at)phc(dot)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(at)postgresql(dot)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(at)Yahoo(dot)com #

_________________________________________________________
Do You Yahoo!?
Get your free @yahoo.com address at http://mail.yahoo.com

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message David Esposito 2002-04-02 14:23:00 Re: Core dump on PG 7.1.3
Previous Message David Esposito 2002-04-02 14:10:52 Re: Core dump on PG 7.1.3