passing a multiple join to a function?

From: Louis-David Mitterrand <vindex+lists-pgsql-sql(at)apartia(dot)org>
To: pgsql-sql(at)postgresql(dot)org
Subject: passing a multiple join to a function?
Date: 2007-12-17 13:06:29
Message-ID: 20071217130629.GA8338@apartia.fr
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Hi,

I've got this ugly case statement that I'd like to hide in a function:

select
...
case when
d.start_date <= CURRENT_DATE and
case when w.show_type in ('cinéma','livre')
then d.start_date >= CURRENT_DATE - 21
else (d.end_date >= CURRENT_DATE or d.end_date is null) end
then '0_actualite'
when
d.start_date > CURRENT_DATE
then '1_agenda'
else '2_archive'
end
as timing
...
from story s
join show w on (s.id_show = w.id_show)
join show_date d on (d.id_show = w.id_show and
d.start_date = (select d2.start_date from show_date d2 where d2.id_show = w.id_show order by d2.end_date >= CURRENT_DATE desc,
d2.start_date limit 1)
)
...

I could very well create a show_timing(int) function that accepts an
id_show and performs its own, additional, multiple join complex query on
story, show_date, and show.

Is there a way of feeding enough data to the function to avoid another
query?

Thanks,

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message danap 2007-12-17 16:56:32 Describe Table
Previous Message Oleg Kharin 2007-12-15 15:15:45 Bad count of rows estimated for emerge join