I wrote a plpgsql function to return the maximum of three dates.
TAL=# select max(req_del_date1, req_del_date2, req_del_date3) as ma1
from invoices;
ma1
------------
2003-02-25
2003-02-25
(2 rows)
However I'm having problems with the following query:
TAL=# select max(req_del_date1, req_del_date2, req_del_date3) as max
from invoices where max <= now();
ERROR: Attribute "max" not found
Why can't the where part of the query see "max"? I've tried aliasing the
returned value but that did not work either:
TAL=# select max(req_del_date1, req_del_date2, req_del_date3) as ma1
from invoices where ma1 <= now();
ERROR: Attribute "ma1" not found
What is wrong with my syntax?
Thanks!
Jc