Re: How does one return rows from plpgsql functions? - Mailing list pgsql-general

From Holger Krug
Subject Re: How does one return rows from plpgsql functions?
Date
Msg-id 20020121191624.A5417@dev12.rationalizer.com
Whole thread Raw
In response to Re: How does one return rows from plpgsql functions?  (Ryan Kirkpatrick <pgsql@rkirkpat.net>)
Responses Re: How does one return rows from plpgsql functions?
Re: How does one return rows from plpgsql functions?
List pgsql-general
On Mon, Jan 21, 2002 at 08:02:46AM -0700, Ryan Kirkpatrick wrote:
>     So, how do I get back and access the entire row returned from a
> function without calling it multiple times? Or is that even possible?
> Thanks.

As I known, their is no straight way to do it. But you can do the
following:

SELECT get_id(p), get_fielda(p) WHERE p = update_get(1);

Here `update_get' allocates space in a memory context like
`CurrentTransactionContext' or what ever is necessary in your case,
puts the resulting typle into the allocated space and returns a
pointer p to that tuple. `get_*' are accessor methods for such a
pointer, accessing the allocated memory and retrieving the values
needed.

To be as type-safe as possible I would recommend to introduce a
special type `PointerToMyTableRow'. The input and output functions of
that type should simply throw an exception (i.e. call
`elog(ERROR,...)'), to avoid that pointers can be externalized.

This all obviously requires some C-coding. But it works and would
solve your problem.


--
Holger Krug
hkrug@rationalizer.com

pgsql-general by date:

Previous
From: Jason Earl
Date:
Subject: Re: [HACKERS] PostgreSQL Licence: GNU/GPL
Next
From: Tom Lane
Date:
Subject: Re: [HACKERS] PostgreSQL Licence: GNU/GPL