Thread: BUG #1630: Wrong conversion in to_date() function. See example.
BUG #1630: Wrong conversion in to_date() function. See example.
From
"Ariel E. Carná/Elizabeth Sosa"
Date:
The following bug has been logged online: Bug reference: 1630 Logged by: Ariel E. Carná/Elizabeth Sosa Email address: acarna@tarifar.com PostgreSQL version: 7.3.8/7.4.6 Operating system: SuSE Linux Description: Wrong conversion in to_date() function. See example. Details: Case PgSQL 7.3.8/SuSE Linux 8.2 (i586) ====================================== PROD=# select to_date('2005-02-32', 'YYYY-MM-DD'); to_date ------------ 2005-03-04 (1 row) PROD=# select version(); version ---------------------------------------------------------------------------- ----------------------------- PostgreSQL 7.3.8 on i686-pc-linux-gnu, compiled by GCC gcc (GCC) 3.3 20030226 (prerelease) (SuSE Linux) (1 row) Case PgSQL 7.4.6/SuSE Linux 9.2 (i586)====================================== PROD=> select to_date('2005-02-32', 'YYYY-MM-DD'); to_date ------------ 04-03-2005 (1 row) PROD=> select version(); version ---------------------------------------------------------------------------- ----------------- PostgreSQL 7.4.6 on i686-pc-linux-gnu, compiled by GCC gcc (GCC) 3.3.4 (pre 3.3.5 20040809) (1 row)
On Tue, Apr 26, 2005 at 11:48:12PM +0100, Ariel E. Carná/Elizabeth Sosa wrote: > > Case PgSQL 7.3.8/SuSE Linux 8.2 (i586) > ====================================== > PROD=# select to_date('2005-02-32', 'YYYY-MM-DD'); > to_date > ------------ > 2005-03-04 > (1 row) > > Case PgSQL 7.4.6/SuSE Linux 9.2 > (i586)====================================== > PROD=> select to_date('2005-02-32', 'YYYY-MM-DD'); > to_date > ------------ > 04-03-2005 > (1 row) What bug are you reporting? These are the same date displayed in different formats -- are you familiar with the DateStyle setting? http://www.postgresql.org/docs/7.3/interactive/datatype-datetime.html#DATATYPE-DATETIME-OUTPUT http://www.postgresql.org/docs/7.4/interactive/datatype-datetime.html#DATATYPE-DATETIME-OUTPUT test=> SELECT version(); version --------------------------------------------------------------------------- PostgreSQL 7.4.7 on sparc-sun-solaris2.9, compiled by GCC gcc (GCC) 3.4.2 (1 row) test=> SET DateStyle TO 'ISO,MDY'; SET test=> SELECT to_date('2005-02-32', 'YYYY-MM-DD'); to_date ------------ 2005-03-04 (1 row) test=> SET DateStyle TO 'Postgres,DMY'; SET test=> SELECT to_date('2005-02-32', 'YYYY-MM-DD'); to_date ------------ 04-03-2005 (1 row) If anything I'd expect 2005-02-32 to be rejected as invalid, but I don't know the history or rationale behind to_date's behavior. -- Michael Fuhr http://www.fuhr.org/~mfuhr/
"Ariel E. Carná/Elizabeth Sosa" <acarna@tarifar.com> writes: > PROD=# select to_date('2005-02-32', 'YYYY-MM-DD'); > to_date > ------------ > 2005-03-04 > (1 row) I'm not convinced that's a bug --- most implementations of the Unix mktime function will handle out-of-range day numbers like that. regards, tom lane
Even javascript handles those dates the same way... On 4/27/05, Tom Lane <tgl@sss.pgh.pa.us> wrote:=20 >=20 > "Ariel E. Carn=C3=A1/Elizabeth Sosa" <acarna@tarifar.com> writes: > > PROD=3D# select to_date('2005-02-32', 'YYYY-MM-DD'); > > to_date > > ------------ > > 2005-03-04 > > (1 row) >=20 > I'm not convinced that's a bug --- most implementations of the Unix > mktime function will handle out-of-range day numbers like that. >=20 > regards, tom lane >=20 > ---------------------------(end of broadcast)--------------------------- > TIP 5: Have you checked our extensive FAQ? >=20 > http://www.postgresql.org/docs/faq >
Michael Fuhr <mike@fuhr.org> writes: > If anything I'd expect 2005-02-32 to be rejected as invalid, but I > don't know the history or rationale behind to_date's behavior. It is rejected by the standard date input converter: regression=# select '2005-02-32'::date; ERROR: date/time field value out of range: "2005-02-32" HINT: Perhaps you need a different "datestyle" setting. However we consider that to_date() exists to be Oracle compatible, and so I would regard this as a bug if and only if Oracle does something different with the same input. Anyone know? regards, tom lane
> > However we consider that to_date() exists to be > Oracle compatible, > and so I would regard this as a bug if and only if > Oracle does > something different with the same input. Anyone > know? > Here is the output I get from Oracle: ===================================================== Connected to: Oracle8 Enterprise Edition Release 8.0.6.3.0 - Production SELECT to_date('2005-02-27', 'YYYY-MM-DD') from dual TO_DATE('2005-02-27','YYYY-MM- ------------------------------ 2/27/2005 1 row selected SELECT to_date('2005-02-29', 'YYYY-MM-DD') from dual ORA-01839: date not valid for month specified SELECT to_date('2005-02-32', 'YYYY-MM-DD') from dual; ORA-01847: day of month must be between 1 and last day of month =========================================== Regards, Shelby Cain __________________________________________________ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com
With Oracle (at least since 6.x version) this conversion is wrong. Atentamente ,=20 Ariel Carn=E1 -----Mensaje original----- De: Tom Lane [mailto:tgl@sss.pgh.pa.us]=20 Enviado el: Mi=E9rcoles, 27 de Abril de 2005 11:54 a.m. Para: Michael Fuhr CC: Ariel E. Carn=C3=A1/Elizabeth Sosa; pgsql-bugs@postgresql.org Asunto: Re: [BUGS] BUG #1630: Wrong conversion in to_date() function. See example.=20 Michael Fuhr <mike@fuhr.org> writes: > If anything I'd expect 2005-02-32 to be rejected as invalid, but I > don't know the history or rationale behind to_date's behavior. It is rejected by the standard date input converter: regression=3D# select '2005-02-32'::date; ERROR: date/time field value out of range: "2005-02-32" HINT: Perhaps you need a different "datestyle" setting. However we consider that to_date() exists to be Oracle compatible, and so I would regard this as a bug if and only if Oracle does something different with the same input. Anyone know? regards, tom lane
On Wed, 2005-04-27 at 10:53 -0400, Tom Lane wrote: > Michael Fuhr <mike@fuhr.org> writes: > > If anything I'd expect 2005-02-32 to be rejected as invalid, but I > > don't know the history or rationale behind to_date's behavior. > > It is rejected by the standard date input converter: > > regression=# select '2005-02-32'::date; > ERROR: date/time field value out of range: "2005-02-32" > HINT: Perhaps you need a different "datestyle" setting. > > However we consider that to_date() exists to be Oracle compatible, > and so I would regard this as a bug if and only if Oracle does > something different with the same input. Anyone know? It's "almost" bug. And it's in TODO (but it's really long todo..:-( I think to_date/timestamp() should be more pedantic. Karel PS. for volunteers for the work on new generation of to_char/date(): http://people.redhat.com/kzak/libfmt/libfmt-0.2-03262005.tar.gz -- Karel Zak <zakkr@zf.jcu.cz>