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