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 1miKTM-0007F4-SV for pgsql-general@arkaria.postgresql.org; Wed, 03 Nov 2021 17:54:52 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1miKTK-0005iz-U1 for pgsql-general@arkaria.postgresql.org; Wed, 03 Nov 2021 17:54:50 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1miKTK-0005io-KI for pgsql-general@lists.postgresql.org; Wed, 03 Nov 2021 17:54:50 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1miKTI-0003lF-BC for pgsql-general@lists.postgresql.org; Wed, 03 Nov 2021 17:54:50 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 1A3HsklV138333; Wed, 3 Nov 2021 13:54:46 -0400 From: Tom Lane To: Bryn Llewellyn cc: pgsql-general list Subject: Re: to_date() and to_timestamp() with negative years In-reply-to: References: Comments: In-reply-to Bryn Llewellyn message dated "Wed, 03 Nov 2021 10:40:34 -0700" MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-ID: <138331.1635962086.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Wed, 03 Nov 2021 13:54:46 -0400 Message-ID: <138332.1635962086@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Bryn Llewellyn writes: > Is there any chance that you might be bold and simply make negative "yea= r" values illegal in "to_date()" and "to_timestamp()" =E2=80=94 just as th= ey already are in "make_timestamp()", "make_timestamptz()", and the "from = text" typecasts to date-time moment values? Uh, what? regression=3D# select make_timestamp(-44,3,15,0,0,0); make_timestamp = ------------------------ 0044-03-15 00:00:00 BC (1 row) The other stuff you are talking about looks like confusion around which characters are minus signs in the data and which ones are field separators. Given the very squishy definitions of to_date/to_timestamp, I'm not surprised if that works only with carefully chosen field layouts --- but it does work for me with all of these cases: regression=3D# select to_date('-0044-03-15', 'YYYY-MM-DD'); to_date = --------------- 0044-03-15 BC (1 row) regression=3D# select to_date('03-15--0044', 'MM-DD-YYYY'); to_date = --------------- 0044-03-15 BC (1 row) regression=3D# select to_date('03/15/-0044', 'MM/DD/YYYY'); to_date = --------------- 0044-03-15 BC (1 row) I'd be the first to agree that that code is a mess and could stand to be rewritten --- but I seriously doubt that we'd take a patch that intentionally breaks cases that work fine today. There's also the angle that these are supposed to be Oracle-compatible, so I wonder what Oracle does with such input. regards, tom lane