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 1miQAx-0003pn-8X for pgsql-general@arkaria.postgresql.org; Thu, 04 Nov 2021 00:00:15 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1miQAv-00027W-8t for pgsql-general@arkaria.postgresql.org; Thu, 04 Nov 2021 00:00:13 +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 1miQAu-00027K-Ax for pgsql-general@lists.postgresql.org; Thu, 04 Nov 2021 00:00:12 +0000 Received: from out5-smtp.messagingengine.com ([66.111.4.29]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1miQAn-0006Go-8Q for pgsql-general@lists.postgresql.org; Thu, 04 Nov 2021 00:00:11 +0000 Received: from compute3.internal (compute3.nyi.internal [10.202.2.43]) by mailout.nyi.internal (Postfix) with ESMTP id E6C4E5C016D; Wed, 3 Nov 2021 20:00:03 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute3.internal (MEProxy); Wed, 03 Nov 2021 20:00:03 -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=j bAzamnX9ze4b4Gb3sfMHdyZ3Z7lDjnXt9ETxE3fDQU=; b=hhtqq91isQwOzUqX3 4JoU+4G+Rb33mTebE4CtKUDfcusuOl0CZpu+QxTi2tV9uH/Ka1sWDQ3lodBXe9W0 JJbIMOYv2Wkk0Fx9kHc7WwptusWWw6per2EnLysCXyRjZGoTcc26zLDxdV8RNd7p 3JHk7GiSbU1tOgk0pTaP2DlYCFVLOboRa8kXhV8DMbZc+MkdRy+O00QYAjmYV2ZH OGQRKpTdH3nij3kbjXPAu8Z3jhd61Te/GUA5DQ8RhRD4KkK1YzeLKuU0Cmh3SvuK zg4aDXFiEIZZxwtJ+hNLvGh15uAu36I6XsZTMwOr7PiKXonsc7sgJXtObMwHrFsY eAbaQ== 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=jbAzamnX9ze4b4Gb3sfMHdyZ3Z7lDjnXt9ETxE3fD QU=; b=DzlLBN5xUf/IhHMOoWc9nXWEi6k5uXh3FvLxyyp44iNcTvnWrsdOb/p/v x0IirE/Wkz6jPa8sFIbNxF7iqQZ13v62SaBVBLx/2swwsKU3bIvcJ465CS5Haev2 lfSeV186wtzmrxigQ6/1Jf/ZLdp815/IYD7D5Jt4KwnxnHdtxcjRUob5ozVmNGcg Jf72DhCfEWLeLBHrn5Y6rIdGMxW7CunHRW/Gvxif5/k8NNnuHYBg0khso/pxWI5e KqIBNMZg+KbwBsGxHUwGUybl95OwyUR4JOlFuu/yOeGJu2KY0IEBA4taRI6Q7yoX OQZMlZv9sz+2JT7LWfgg/bVznv0iQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvuddrtdefgddugecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenuc fjughrpefkffggfgfuvfhfhfgjtgfgsehtkeertddtfeejnecuhfhrohhmpeetughrihgr nhcumfhlrghvvghruceorggurhhirghnrdhklhgrvhgvrhesrghklhgrvhgvrhdrtghomh eqnecuggftrfgrthhtvghrnhepleekgeejhfekteehfeduveetheeivdduheekudelteef vdffueehtddvgedtfeefnecuffhomhgrihhnpehpohhsthhgrhgvshhqlhdrohhrghenuc evlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpegrughrihgr nhdrkhhlrghvvghrsegrkhhlrghvvghrrdgtohhm X-ME-Proxy: Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 3 Nov 2021 20:00:02 -0400 (EDT) Message-ID: Date: Wed, 3 Nov 2021 17:00:01 -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> <72204b8f-41b2-0004-b09b-842f8c57477f@aklaver.com> <0B75398B-91CC-4074-B77A-390AA157685B@yugabyte.com> <265331.1635978234@sss.pgh.pa.us> <745E3531-6791-4964-AF68-BC82FC2EC864@yugabyte.com> From: Adrian Klaver In-Reply-To: <745E3531-6791-4964-AF68-BC82FC2EC864@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 15:56, Bryn Llewellyn wrote: >> tgl@sss.pgh.pa.us wrote: >> >> Adrian Klaver writes: >>> Haven't had time to work through what the above is actually doing. >> >> I think the first two are explained by 489c9c340: >> >> Also, arrange for the combination of a negative year and an >> explicit "BC" marker to cancel out and produce AD. This is how >> the negative-century case works, so it seems sane to do likewise. >> >> The last two look like a parsing issue: with no field separator (nope, the space doesn't count), the code is taking the dash as a field separator. > > Thanks, Adrian, for trying those tests. So if PG is aiming for one consistent story for years that are less than one, in all three APIs (to_date() and its cousins, make_timestamp[tz](), and text-to-date-time typecasts), then work still remains. > > The parsing problem seems to be a separable annoyance. I assume that Tom’s "nope, the space doesn't count” is a narrow comment on this corner of the implementation. It definitely counts here: > > select to_date('12345 01 01', 'YYYY MM DD'); > > And you have to have some kind of separator between the years substring and the adjacent one(s) even to succeed with years that have more than four digits. Another usage note stresses that while this is OK: > > select to_date('12340101', 'YYYYMMDD'); > > this isn't: > > select to_date('123450101', 'YYYYMMDD'); It does with a tweak: select to_date('12345 0101', 'FMYYYYMMDD'); to_date ------------- 12345-01-01 > > and nor is anything else that you might dream up that does not have a separator as mentioned above. > > Tom asked about Oracle Database. I have a still-working Version 18.0 in a VM on my laptop. The query can't be so terse there because there's no implicit typecast from date to text. And there's the famous annoyance of "dual". If you go here: https://www.postgresql.org/docs/current/functions-formatting.html and search on Oracle you will see that there are other exceptions. Like most things there is not complete agreement on how closely to follow someone else's code. > > I tried this first: > > select to_char(to_date('1234/01/01', 'YYYY/MM/DD'), 'YYYY/MM/DD') from dual; > > It gets the same output back as the input you gave. So far so good. Then I changed the input to '-1234/01/01'. It caused this error: > > ORA-01841: (full) year must be between -4713 and +9999, and not be 0 > > So it seems that Oracle Database has its own problems. But at least the wording "must… not be 0" is clear—and not what PG wants to support. > -- Adrian Klaver adrian.klaver@aklaver.com