Re: How does one return rows from plpgsql functions?

From: Holger Krug <hkrug(at)rationalizer(dot)com>
To: Ryan Kirkpatrick <pgsql(at)rkirkpat(dot)net>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: How does one return rows from plpgsql functions?
Date: 2002-01-21 18:16:24
Message-ID: 20020121191624.A5417@dev12.rationalizer.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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(at)rationalizer(dot)com

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Andrew Gould 2002-01-21 18:20:29 Re: frustration with database size <long>
Previous Message Vince Vielhaber 2002-01-21 18:10:24 Re: [HACKERS] PostgreSQL Licence: GNU/GPL