Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kE0QO-0006E9-5z for pgsql-hackers@arkaria.postgresql.org; Fri, 04 Sep 2020 01:21:56 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1kE0QM-0004hY-6m for pgsql-hackers@arkaria.postgresql.org; Fri, 04 Sep 2020 01:21:54 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kE0QL-0004hQ-WE for pgsql-hackers@lists.postgresql.org; Fri, 04 Sep 2020 01:21:54 +0000 Received: from momjian.us ([72.94.173.45]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kE0QJ-0005oM-Od for pgsql-hackers@lists.postgresql.org; Fri, 04 Sep 2020 01:21:52 +0000 Received: from bruce by momjian.us with local (Exim 4.92) (envelope-from ) id 1kE0QH-0008WS-BE; Thu, 03 Sep 2020 21:21:49 -0400 Date: Thu, 3 Sep 2020 21:21:49 -0400 From: Bruce Momjian To: "David G. Johnston" Cc: Laurenz Albe , PostgreSQL Hackers Subject: Re: BUG #16419: wrong parsing BC year in to_date() function Message-ID: <20200904012149.GA13932@momjian.us> References: <16419-d8d9db0a7553f01b@postgresql.org> <0123b852ae3fe53eca11b9451d035411b06dafd5.camel@cybertec.at> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: User-Agent: Mutt/1.10.1 (2018-07-13) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On Wed, Jul 15, 2020 at 09:26:53AM -0700, David G. Johnston wrote: > On Tue, May 12, 2020 at 8:56 PM Laurenz Albe wrote: > > On Tue, 2020-05-12 at 18:09 -0700, David G. Johnston wrote: > > Redirecting to -hackers for visibility.  I feel there needs to be > something done here, even if just documentation (a bullet in the usage > notes section - and a code comment update for the macro) > > pointing this out and not changing any behavior. > > Since "to_date" is an Oracle compatibility function, here is what Oracle > 18.4 has to say to that: > > SQL> SELECT to_date('0000', 'YYYY') FROM dual; > SELECT to_date('0000', 'YYYY') FROM dual >                * > ERROR at line 1: > ORA-01841: (full) year must be between -4713 and +9999, and not be 0 > > > > Attached is a concrete patch (back-patchable hopefully) documenting the current > reality. > > As noted in the patch commit message (commentary really): > > make_timestamp not agreeing with make_date on how to handle negative years > should probably just be fixed - but that is for someone else to handle. > > Whether to actually change the behavior of to_date is up for debate though I > would presume it would not be back-patched. OK, so, looking at this thread, we have to_date() treating -1 as -2 BC, make_date() treating -1 as 1 BC, and we have Oracle, which to_date() is supposed to match, making -1 as 1 BC. Because we already have the to_date/make_date inconsistency, and the -1 to -2 BC mapping is confusing, and doesn't match Oracle, I think the clean solution is to change PG 14 to treat -1 as 1 BC, and document the incompatibility in the release notes. -- Bruce Momjian https://momjian.us EnterpriseDB https://enterprisedb.com The usefulness of a cup is in its emptiness, Bruce Lee