Re: date versus datetime? - Mailing list pgsql-sql

From Tom Lane
Subject Re: date versus datetime?
Date
Msg-id 18511.902002588@sss.pgh.pa.us
Whole thread Raw
In response to date versus datetime?  (Eric McKeown <ericm@palaver.net>)
List pgsql-sql
Eric McKeown <ericm@palaver.net> writes:
> for instance, it seems I can do this with the date type:
> select * from table where date_field < some_date_I_specify_here
> However, if my reading of the manual and my experiments are correct, I
> can't perform that sort of operation with the datetime type.

You certainly can do that with datetime; I do it all the time.
Without seeing a concrete example, I'm not sure why it's not working for
you.  Perhaps you are writing the comparison date in a format that's
acceptable for type "date" but not for "datetime"?  That doesn't seem
very likely though; datetime's parser is relatively flexible.

There are a couple of gotchas in writing datetime constants in SQL
commands.  You have to put quotes around them (they're strings as
far as the parser is concerned).  For example,
    select * from ohistory where ordertime < 'jun 10 1998 16:00';
In some situations you may have to explicitly cast the string constant
to datetime type:
    select * from ohistory where ordertime < 'jun 10 1998 16:00'::datetime;
but I find Postgres usually manages to figure out for itself that a
datetime value is wanted.

As far as I know those gotchas also apply to date constants, however.
So I'm still confused about why one works and not the other for you.

            regards, tom lane

pgsql-sql by date:

Previous
From: Marc Howard Zuckman
Date:
Subject: Re: [SQL] pg_time
Next
From: Sascha Schumann
Date:
Subject: int/bit fields