Re: date comparisons - Mailing list pgsql-general

From Richard Huxton
Subject Re: date comparisons
Date
Msg-id 457EE548.6030705@archonet.com
Whole thread Raw
In response to Re: date comparisons  ("Belinda M. Giardine" <giardine@bio.cse.psu.edu>)
List pgsql-general
Belinda M. Giardine wrote:
> Thanks that works.  But I am trying to understand why the others did not,
> especially my first attempt.  Further testing shows that
>
> select id, date_entered from main_table where
> date_entered >= to_timestamp('2006 January', 'YYYY Month');
>
> works, but
>
> select id, date_entered from main_table where
> date_entered >= to_timestamp('January 2006', 'Month YYYY');
>
> does not.  The order of the fields in the to_timestamp function changes
> the timestamp produced.  Should it be this way?

No. Good testing, you've found a bug. Seems to be a problem with the
"Month" formatting if there's more fields after it.

> hbvar=# select to_timestamp('January 2006', 'Month YYYY');
>       to_timestamp
> ------------------------
>  0006-01-01 00:00:00-05
> (1 row)
>
> hbvar=# select to_timestamp('2006 January', 'YYYY Month');
>       to_timestamp
> ------------------------
>  2006-01-01 00:00:00-05
> (1 row)

SELECT to_timestamp('January 22 2006','Month DD YYYY');
       to_timestamp
------------------------
  0005-06-28 00:00:00+00
(1 row)

SELECT to_timestamp('Jan 22 2006','Mon DD YYYY');
       to_timestamp
------------------------
  2006-01-22 00:00:00+00
(1 row)

If you report this bug using the form below, I'm sure one of the
developers will have a patch out shortly.
   http://www.postgresql.org/support/submitbug

Good catch!
--
   Richard Huxton
   Archonet Ltd

pgsql-general by date:

Previous
From: "Marc Mamin"
Date:
Subject: Re: a question on SQL
Next
From: Tom Lane
Date:
Subject: Re: resetting sequence to cur max value