current_date vs 'now'

From: Jamie Tufnell <diesql(at)googlemail(dot)com>
To: pgsql-sql <pgsql-sql(at)postgresql(dot)org>
Subject: current_date vs 'now'
Date: 2009-02-05 06:05:28
Message-ID: b0a4f3350902042205l6ba4f2c0u2545992fbb7e9088@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Hi,

I was doing EXPLAIN ANALYZE on a query where I compare against
current_date and noticed the following:

Filter: (date <= ('now'::text)::date)

I knew about now() but did not know about 'now' and have since learnt
of 'today', 'tomorrow', etc. Great!

So, I changed my condition to <= 'now' to see if there would be any
improvement, which changed the filter line to:

Filter: (date <= '2009-02-05'::date)

and without fail this query is 2ms quicker every time. I alternated
between the two and ran them both several times to make sure it wasn't
just a cache difference.

AFAIK current_date is standard and 'now' and 'today', etc are not...
so that's one reason to continuing using current_date. However, I
wonder why 'today' and current_date don't generate the same query
plan?

Jamie

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Tom Lane 2009-02-05 15:34:06 Re: current_date vs 'now'
Previous Message Chris 2009-02-04 22:42:54 Re: postgre2postgre