Re: return setof : alternatives to holder table - Mailing list pgsql-general

From Mike Christensen
Subject Re: return setof : alternatives to holder table
Date
Msg-id AANLkTikzwN0t9+d-PURik2fpJ8UvOQ439oCJF5qPD0GZ@mail.gmail.com
Whole thread Raw
In response to Re: return setof : alternatives to holder table  (Craig Ringer <craig@postnewspapers.com.au>)
Responses Re: return setof : alternatives to holder table
Re: return setof : alternatives to holder table
List pgsql-general
On Sun, Aug 15, 2010 at 3:10 AM, Craig Ringer <craig@postnewspapers.com.au> wrote:
On 15/08/10 18:00, zhong ming wu wrote:

> Thanks for any better solution to this

CREATE TYPE

However, you still have to have a special type around just for that
function, and you have to *maintain* it to ensure it always matches the
types/columns of the input tables.

I frequently wish for type inference in PL/PgSQL functions returning
query results, so Pg could essentially create and destroy a type along
with the function, allowing you to reference columns in the functions
results without having to use RETURNS RECORD and all that AS
(column-list) pain.

Of course, I don't want it badly enough to put my time where my mouth is
and try to code it ;-) . I'm not whining about the current situation,
just thinking about ways it could improve further.



How about just using OUT parameters?

CREATE FUNCTION FOO(IN _id uuid, OUT col1 text, OUT col2 text)
   RETURNS SETOF record AS
   BEGIN
      select col1, col2 from test where id=_id;
   END;

Then your output just has to match the signature of the OUT parameters.  And you don't need to define anything when you call it.

Mike

pgsql-general by date:

Previous
From: "A. Kretschmer"
Date:
Subject: Re: return setof : alternatives to holder table
Next
From: Craig Ringer
Date:
Subject: Re: return setof : alternatives to holder table