On Tue, 3 Dec 2002, Magnus Naeslund(f) wrote: > Now convert this query so that it only evaluates the date_part thing > ONCE:
That's not a good idea as long as t.stamp varies from row to row. ;) Perhaps once per row, maybe... :) > select t.id, date_part('days',now()-t.stamp) from table_name t where > date_part('days',now()-t.stamp) > 20; Potentially I think something like this would do it: select t.id, t.foo from (select id, date_part('days', now()-stamp) as foo from table_name except select null, null) as t where foo>20; It's not really an optimization given the required except, but if there was some way to tell the system not to push clauses down into a subselect you wouldn't even need that. ---------------------------(end of broadcast)--------------------------- TIP 1: subscribe and unsubscribe commands go to [EMAIL PROTECTED]