Re: SETOF - Mailing list pgsql-sql

From Greg Stark
Subject Re: SETOF
Date
Msg-id 8765qy9dzd.fsf@stark.dyndns.tv
Whole thread Raw
In response to Re: SETOF  (Christoph Haller <ch@rodos.fzk.de>)
List pgsql-sql
Christoph Haller <ch@rodos.fzk.de> writes:

> You cannot obtain several columns from SQL functions.
> See the list archives (search for SETOF) for details.
> You have to use e.g. a plpgsql function instead.

How do you do it with a plpgsql function?


FWIW, this is probably the thing I wish for the most often. I can't count how
many times I've wanted to be able to write queries like:

select *,       (select x,y,z    from b where b.id = a.foo)      (select xx,yy,zz from c where c.id = a.bar) from a

As it is I either have to find a way to turn it into a join, which isn't
always possible, or duplicate the subquery which can cause multiple identical
table lookups.

I suppose one alternative would be for postgres to check if there are multiple
subplans to see if the subplan is the same except for the returned columns and
merge them somehow.

That doesn't solve the case of when you want a function that returns two
columns though.

-- 
greg



pgsql-sql by date:

Previous
From: Christoph Haller
Date:
Subject: Re: SETOF
Next
From: Christoph Haller
Date:
Subject: Re: SETOF