Re: Need help with embedded CASEs

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: Need help with embedded CASEs
Дата
Msg-id 5450.1005156396@sss.pgh.pa.us
обсуждение исходный текст
Ответ на Need help with embedded CASEs  (Denis Bucher <dbucher@niftycom.com>)
Список pgsql-sql
Denis Bucher <dbucher@niftycom.com> writes:
> SELECT CASE WHEN '2001-11-07' = current_date THEN 't' ELSE 'f' END AS 
> flag_today, CASE WHEN flag_today THEN current_time ELSE '00:00' END AS 
> time_iftoday;

> Why doesn't it work ?

flag_today is an output variable of this SELECT, not an input.

> Or how could I use the result of the CASE in another ?

AFAIK the only way to avoid writing the expression twice is to use
a sub-select:

SELECT ss.flag_today,      CASE WHEN ss.flag_today THEN current_time ELSE '00:00' END AS time_iftoday
FROM
(SELECT CASE WHEN '2001-11-07' = current_date THEN true ELSE false END AS 
flag_today) AS ss;
        regards, tom lane


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

Предыдущее
От: Tom Lane
Дата:
Сообщение: Re: RIGHT JOIN is only supported with mergejoinable join conditions
Следующее
От: "Nick Fankhauser"
Дата:
Сообщение: Re: RIGHT JOIN is only supported with mergejoinable join conditions