Re: Need help with embedded CASEs

Поиск
Список
Период
Сортировка
От Peter Eisentraut
Тема Re: Need help with embedded CASEs
Дата
Msg-id Pine.LNX.4.30.0111072102530.835-100000@peter.localdomain
обсуждение исходный текст
Ответ на Need help with embedded CASEs  (Denis Bucher <dbucher@niftycom.com>)
Список pgsql-sql
Denis Bucher 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 ?

For one thing, flag_today is not a made boolean expression, so the second
CASE wouldn't even work on that account.  Secondly, the "AS" aliases in
the select list aren't available as variables in the other items in the
select list.

A corrected version would be:

SELECT   CASE WHEN DATE '2001-11-07' = current_date THEN true ELSE false END       AS flag_today,   CASE WHEN DATE
'2001-11-07'= current_date THEN current_time ELSE TIME '00:00' END       AS time_iftoday;
 

Or shorter:

SELECT   DATE '2001-11-07' = current_date AS flag_today,   CASE WHEN DATE '2001-11-07' = current_date THEN current_time
ELSETIME '00:00' END       AS time_iftoday;
 

-- 
Peter Eisentraut   peter_e@gmx.net



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

Предыдущее
От: Tom Lane
Дата:
Сообщение: Re: RIGHT JOIN is only supported with mergejoinable join conditions
Следующее
От: Roberto Mello
Дата:
Сообщение: ISO SQL 92/99 paper?