Re: 7.4 Wishlist
Dennis Bjorklund <db@zigo.dhs.org>
From: Dennis Björklund <db@zigo.dhs.org>
To: "Magnus Naeslund(f)" <mag@fbab.net>
Cc: Bruce Momjian <pgman@candle.pha.pa.us>, <pgsql-hackers@postgresql.org>
Date: 2002-12-03T09:20:23Z
Lists: pgsql-hackers, pgsql-general
On Tue, 3 Dec 2002, Magnus Naeslund(f) wrote:
> Now convert this query so that it only evaluates the date_part thing
> ONCE:
>
> select t.id, date_part('days',now()-t.stamp) from table_name t where
> date_part('days',now()-t.stamp) > 20;
Something like this could work:
select *
from (select t.id, date_part('days',now()-t.stamp) AS d
from table_name t) AS t1
where t1.d > 20;
That aside I also would like some sort of local names. Something like the
let construct used in many functional languages (not exaclty what you want
above, but still):
let t1 = select * from foo;
t2 = select * from bar;
in select * from t1 natural join t2;
But even though I would like to give name to subexpressions like above, I
still think postgresql should stick to standards as close as possible.
--
/Dennis