Re: How to join function with a table?

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: How to join function with a table?
Дата
Msg-id 15302.1123303620@sss.pgh.pa.us
обсуждение исходный текст
Ответ на How to join function with a table?  (Yudie Pg <yudiepg@gmail.com>)
Ответы Re: How to join function with a table?  (Yudie Pg <yudiepg@gmail.com>)
Список pgsql-general
Yudie Pg <yudiepg@gmail.com> writes:
>  I have a function returning set of date called datelist(date,date)
> ...
>  I would like to join this function with a table
> create table payment(
>  id int4 not null,
>  date_start date,
>  date_end date
> )
> ...
>   I thought simple join like this would work, but it doesn't
> select * from payment P, datelist(P.date_start, P.date_end)

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

В списке pgsql-general по дате отправления:

Предыдущее
От: Brendan Jurd
Дата:
Сообщение: timestamp default values
Следующее
От: Tom Lane
Дата:
Сообщение: Re: timestamp default values