Re: How to join function with a table? - Mailing list pgsql-general

From Yudie Pg
Subject Re: How to join function with a table?
Date
Msg-id e460d0c050808155770e29933@mail.gmail.com
Whole thread Raw
In response to Re: How to join function with a table?  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-general
On 8/5/05, Tom Lane <tgl@sss.pgh.pa.us> wrote:
Certainly not --- per the SQL spec, different elements of a FROM list
are independent, so the datelist relation can't refer to P.
(I think SQL 2003 has a construct called LATERAL that would allow
such things, but we don't implement that yet.)

The only way to do this at the moment in Postgres is to put the
set-returning function into the SELECT target list:

       select id, datelist(date_start, date_end) from payment;

which will work fine if datelist() is implemented as a SQL function,
and not so fine if it's implemented in plpgsql.  You can work around
this by wrapping the plpgsql function in a SQL function (ick).
I posted an example in another thread a day or so ago.

                       regards, tom lane
 
This wraping works! Thanks Tom.
 
create function datelist_sql(date, date) returns setof date as'

select * from datelist($1,$2)

'language 'sql' strict immutable;

 
Then simply do this query
"select datelist('8/1/2005', '8/6/2005')"
 
otherwise with plpgsql function I got
ERROR:  set-valued function called in context that cannot accept a set

pgsql-general by date:

Previous
From: Tony Caduto
Date:
Subject: Re: Simple PG Sql question (i hope)
Next
From: Adrian Klaver
Date:
Subject: plpythonu and return void