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