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 1miOX6-00080C-A3 for pgsql-general@arkaria.postgresql.org; Wed, 03 Nov 2021 22:15:00 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1miOX5-0000cz-2K for pgsql-general@arkaria.postgresql.org; Wed, 03 Nov 2021 22:14:59 +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 1miOX3-0000cQ-Hl for pgsql-general@lists.postgresql.org; Wed, 03 Nov 2021 22:14:58 +0000 Received: from wout1-smtp.messagingengine.com ([64.147.123.24]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1miOWz-0005OZ-SS for pgsql-general@lists.postgresql.org; Wed, 03 Nov 2021 22:14:56 +0000 Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.west.internal (Postfix) with ESMTP id C0CE6320070D; Wed, 3 Nov 2021 18:14:51 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute4.internal (MEProxy); Wed, 03 Nov 2021 18:14:52 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aklaver.com; h= subject:to:cc:references:from:message-id:date:mime-version :in-reply-to:content-type:content-transfer-encoding; s=fm1; bh=A YVyXKgPivDXIeNsbUNgTEf/F52l9ThwLYiR7uPMb38=; b=cFpauIHFntkwMMRWO SOfXjIsdcdFlkyV4PF6O3Da962fm8BRzP2xWMVeRMwpUxSmX25XkyJa73h9pL2OR q6/dYe/QSDxUzTuOcojhNdceDUqLR0wPYlEFQKJRBaWieoC9+bVESX7DP9TFJlyH F0K5tu5LIhjqYO92fdL+vy0jlCLy4VKs/hjcRu6NG1KSbpBBQcdTddMaratpAYQV JT3kTHFO25r5iaWoEVAiNyOAJFquwsgW2wpL5txoEdzStPgC43JSSI/TBeagttbG brMS2nndNr9/XmvxLZcOiU5Dqo33nYyk5i4gOrM17VFxHRROh3C0VLNOYHkt/jmg uQTLg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm1; bh=AYVyXKgPivDXIeNsbUNgTEf/F52l9ThwLYiR7uPMb 38=; b=adqswGVud/aRlVj+NyGpKLnH6M4mNlXU4wr6bLpWYix0S4PyUfgxJSiwA J2aFaxt79EpB7plXCtympTVipNFWVbsujd/n5K8KoI/pPRe240raGhBs4xGl1GZL 1I5wAKwNvnXyzx8CRwbNke8s5fZBXFsIldRfSXtj3928IyM+2DfqnsGdM5E4W+az FD4okl1Mev6QGIpubBu5Q42y+H9WveDrggpM1dHgDChLy9Hu/JmnyLIgx1Cahvbd /NgqvMicjr+y8JFNgKhE0kmfr/XPd4Q1wgd2THoc/6fO9M7yi8sIo9uyIzI7JpuB zldJMp5AsctrxkGqx24mxJOFZOI+g== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvuddrtddvgdduheehucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepuffvfhfhkffffgggjggtgfesthekredttdefjeenucfhrhhomheptegurhhi rghnucfmlhgrvhgvrhcuoegrughrihgrnhdrkhhlrghvvghrsegrkhhlrghvvghrrdgtoh hmqeenucggtffrrghtthgvrhhnpeevveefveefueegffekkefhgeeiueffgfetueejvdfg hfeujeejhfekjeelgedtgeenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmh grihhlfhhrohhmpegrughrihgrnhdrkhhlrghvvghrsegrkhhlrghvvghrrdgtohhm X-ME-Proxy: Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 3 Nov 2021 18:14:50 -0400 (EDT) Subject: Re: to_date() and to_timestamp() with negative years To: Bryn Llewellyn Cc: Tom Lane PostgreSQL , pgsql-general list References: <138332.1635962086@sss.pgh.pa.us> <08E63AD5-8E6D-4140-AE1C-9DC22324A287@yugabyte.com> <72204b8f-41b2-0004-b09b-842f8c57477f@aklaver.com> <0B75398B-91CC-4074-B77A-390AA157685B@yugabyte.com> From: Adrian Klaver Message-ID: Date: Wed, 3 Nov 2021 15:14:49 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.7.0 MIME-Version: 1.0 In-Reply-To: <0B75398B-91CC-4074-B77A-390AA157685B@yugabyte.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 11/3/21 1:39 PM, Bryn Llewellyn wrote: > /adrian.klaver@aklaver.com wrote:/ > >> /Bryn wrote:/ >> >>> In what PG version did you run your test? >>> I'm not surprised that grandfathered-in "solution" that I described >>> will never go away—despite its questionable conceptual basis. > > Thanks, Adrian. What results do these queries give in Version 14? > (Forgive me, I'll make time to install v14 very soon.) select version(); version ------------------------------------------------------------------------------------ PostgreSQL 14.0 on x86_64-pc-linux-gnu, compiled by gcc (SUSE Linux) 7.5.0, 64-bit > > select make_timestamp(0,1,1,0,0,0); ERROR: date field value out of range: 0-01-01 > select make_timestamp(-0,1,1,0,0,0); ERROR: date field value out of range: 0-01-01 > > select '-0001-01-01'::date; -- and similar for typecasts to timestamp > and timestamptz ERROR: invalid input syntax for type date: "-0001-01-01" LINE 1: select '-0001-01-01'::date; > > select '0000-01-01'::date; ERROR: date/time field value out of range: "0000-01-01" LINE 1: select '0000-01-01'::date; > > select '-0000-01-01'::date; ERROR: invalid input syntax for type date: "-0000-01-01" LINE 1: select '-0000-01-01'::date; > > select >   to_date( '15/06/-2021',    'DD/MM/YYYY'    ) as a1, >   to_date( '15/06/-2021 BC', 'DD/MM/YYYY/AD' ) as a2, >   ''                                           as "-", >   to_date( '15 06 -2021',    'DD MM YYYY'    ) as b1, >   to_date( '15 06 -2021 BC', 'DD MM YYYY AD' ) as b2; > a1 | a2 | - | b1 | b2 ---------------+------------+---+------------+--------------- 2021-06-15 BC | 2021-06-15 | | 2021-06-15 | 2021-06-15 BC Haven't had time to work through what the above is actually doing. -- Adrian Klaver adrian.klaver@aklaver.com