Received: from maia.hub.org (maia-5.hub.org [200.46.204.29]) by mail.postgresql.org (Postfix) with ESMTP id C834DB5DBCC for ; Tue, 19 Jul 2011 22:03:49 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.29]) (amavisd-maia, port 10024) with ESMTP id 50990-05 for ; Wed, 20 Jul 2011 01:03:43 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from momjian.us (momjian.us [70.90.9.53]) by mail.postgresql.org (Postfix) with ESMTP id 78F28B5D944 for ; Tue, 19 Jul 2011 22:03:43 -0300 (ADT) Received: (from bruce@localhost) by momjian.us (8.11.6/8.11.6) id p6K13ix10517; Tue, 19 Jul 2011 21:03:44 -0400 (EDT) From: Bruce Momjian Message-Id: <201107200103.p6K13ix10517@momjian.us> Subject: Re: to_char() accepting invalid dates? In-Reply-To: To: Thomas Kellerer Date: Tue, 19 Jul 2011 21:03:44 -0400 (EDT) CC: pgsql-sql@postgresql.org X-Mailer: ELM [version 2.4ME+ PL124 (25)] MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="US-ASCII" X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-3.093 tagged_above=-5 required=5 tests=BAYES_00=-1.9, RP_MATCHES_RCVD=-1.193 X-Spam-Level: X-Archive-Number: 201107/84 X-Sequence-Number: 35654 Thomas Kellerer wrote: > Bruce Momjian, 19.07.2011 00:02: > >>>> postgres=> select to_date('20110231', 'yyyymmdd'); > >>>> > >>>> to_date > >>>> ------------ > >>>> 2011-03-03 > >>>> (1 row) > >>>> > >>>> is there a way to have to_date() raise an exception in such a case? > >>> > >>> it's possible the odd behaviour you get is required by some standard. > >> > >> That would be *very* odd indeed. > >> > >> > >>> jasen=# select '20110303'::date; > >> Thanks for the tip, this was more a question regarding _why_ to_char() behaves this way. > > > > Well, to_char() is based on Oracle's to_char(). How does Oracle handle > > such a date? > > Oracle throws an error for the above example: > > SQL> select to_date('20110231', 'YYYYMMDD') from dual; > select to_date('20110231', 'YYYYMMDD') from dual > * > ERROR at line 1: > ORA-01839: date not valid for month specified > > SQL> OK, it's a bug then. Let me see if I can find a fix for it. -- Bruce Momjian http://momjian.us EnterpriseDB http://enterprisedb.com + It's impossible for everything to be true. +