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 1miM57-0001pt-JS for pgsql-general@arkaria.postgresql.org; Wed, 03 Nov 2021 19:37:58 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1miM54-0007Cv-BY for pgsql-general@arkaria.postgresql.org; Wed, 03 Nov 2021 19:37:54 +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 1miM52-00075K-Tb for pgsql-general@lists.postgresql.org; Wed, 03 Nov 2021 19:37:54 +0000 Received: from wout3-smtp.messagingengine.com ([64.147.123.19]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1miM4u-0004cT-IZ for pgsql-general@lists.postgresql.org; Wed, 03 Nov 2021 19:37:52 +0000 Received: from compute6.internal (compute6.nyi.internal [10.202.2.46]) by mailout.west.internal (Postfix) with ESMTP id 387A63200A47; Wed, 3 Nov 2021 15:37:40 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute6.internal (MEProxy); Wed, 03 Nov 2021 15:37:40 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aklaver.com; h= message-id:date:mime-version:subject:to:cc:references:from :in-reply-to:content-type:content-transfer-encoding; s=fm1; bh=+ LXP51ic3zUtXdguo85B7nzv52PH+qJmBKbQB2YchYc=; b=qArIXBUvPanBEV4yZ jMRDIFVtq+wOL7uplYxugrBDCzVVv65srfTM8ZzKXToXmpSgSmzK7+upJnJCfFud f+GDIPvP4rnhlXsf1VeXi/oMaj7G8ztzTWDePZxal686gYBdX6FCtYQ3vgecAoht GXqeLyf1Q0WQZgOUdl9VtmkdvEDmtsDug/Go8RrG2z2NaijCRAphVPgJxWu+Roem 4T9xUCxUbdte7uzsh4hOTTglp3avm7i5wYu88Rhe+VcqDHZ2puCkcWoAslbibYSV LO9r2LmAjsx6X1PDdyw0dgbOyPYHbKtshCc1mjk+hCbPP48tkcf78gE0TRDe7iML 03asw== 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=+LXP51ic3zUtXdguo85B7nzv52PH+qJmBKbQB2Ych Yc=; b=Jb0mPsaIhyONcpiCPqlp2clBTaohNZixcE1ya0PXQQMHnp5EuKs/QZdmG qLacMq7d4Y6qYNu7IQcWVKBB9jerB9nVE7usNy112PLmBwTOL0ZqnbWZU//fRPd3 1Mx7u9ogVIjMKxjW9hw4Ivj2pmO88yhInKTCx00MLy0Tzr/aTNHhLahFeEg3H+MM f64mVCoXcX8i59JYowSlmDnGY8xmSPeV3TJQl8iP8eEWc5MLa+FYnZDCRc3FvHQ2 rS8a1L80VnKT8I7QrKmjg7lNES4r0pYtQ80lpG1PKDD4rX+UVRlR1YzKODcmeU6u HzdzAg+4z78sMIq1QBXaNzCluSjoA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvuddrtddvgdduvdegucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepkfffgggfuffvfhfhjggtgfesthekredttdefjeenucfhrhhomheptegurhhi rghnucfmlhgrvhgvrhcuoegrughrihgrnhdrkhhlrghvvghrsegrkhhlrghvvghrrdgtoh hmqeenucggtffrrghtthgvrhhnpeelkeegjefhkeetheefudevteehiedvudehkeduleet fedvffeuhedtvdegtdeffeenucffohhmrghinhepphhoshhtghhrvghsqhhlrdhorhhgne cuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomheprggurhhi rghnrdhklhgrvhgvrhesrghklhgrvhgvrhdrtghomh X-ME-Proxy: Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 3 Nov 2021 15:37:38 -0400 (EDT) Message-ID: <72204b8f-41b2-0004-b09b-842f8c57477f@aklaver.com> Date: Wed, 3 Nov 2021 12:37:38 -0700 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.2.1 Subject: Re: to_date() and to_timestamp() with negative years Content-Language: en-US To: Bryn Llewellyn , Tom Lane PostgreSQL Cc: pgsql-general list References: <138332.1635962086@sss.pgh.pa.us> <08E63AD5-8E6D-4140-AE1C-9DC22324A287@yugabyte.com> From: Adrian Klaver In-Reply-To: <08E63AD5-8E6D-4140-AE1C-9DC22324A287@yugabyte.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 11/3/21 11:18, Bryn Llewellyn wrote: >> tgl@sss.pgh.pa.us wrote: >> >> Bryn Llewellyn writes: >>> Is there any chance that you might be bold and simply make negative "year" values illegal in "to_date()" and "to_timestamp()" — just as they already are in "make_timestamp()", "make_timestamptz()", and the "from text" typecasts to date-time moment values? >> >> Uh, what? >> >> regression=# 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=# select to_date('-0044-03-15', 'YYYY-MM-DD'); >> to_date >> --------------- >> 0044-03-15 BC >> (1 row) >> >> regression=# select to_date('03-15--0044', 'MM-DD-YYYY'); >> to_date >> --------------- >> 0044-03-15 BC >> (1 row) >> >> regression=# 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. > > I just ran your test: > > select make_timestamp(-44,3,15,0,0,0); > > in each of the three environments that I mentioned—but especially, therefore, in PG 13.4 (on macOS). > > It cased the error that I mentioned: > > ERROR: 22008: date field value out of range: -44-03-15 > > It's the same with "make_timestamp()". https://www.postgresql.org/docs/14/release-14.html#id-1.11.6.5.3 " Allow make_timestamp()/make_timestamptz() to accept negative years (Peter Eisentraut) Negative values are interpreted as BC years. " > 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. > > > > -- Adrian Klaver adrian.klaver@aklaver.com