Your decision is in order. If dates are literals, I would prefer:
WHERE datefield >= '2010-01-01 00:00:00' AND datefield < '2012-01-01 00:00:00'
This is done in exactly the same way, but is more amenable to support since it clearly states that each literal date is a timestamp, not a date. For example, suppose someone changes your request to the next
AND datefield <= '2012-01-01'
... waiting (and could not) include in the request the full day "2012-01-01". With later syntax, intent becomes clearer, and this confusion is prevented.
To make it even more understandable (perhaps too verbose), you can do an explicit cast:
WHERE datefield >= '2010-01-01 00:00:00'::timestamp AND datefield < '2012-01-01 00:00:00'::timestamp
I would not use to_date() here for similar reasons (potential data type confusion) rather than to_timestamp() (it returns timestamptz ).
By the way, I changed the case to fit the recommended practice (keywords in upper case, identifiers in lower case)
leonbloy
source share