Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1isT6M-0006db-Bu for pgsql-bugs@arkaria.postgresql.org; Fri, 17 Jan 2020 14:59:58 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1isT6K-00047u-TT for pgsql-bugs@arkaria.postgresql.org; Fri, 17 Jan 2020 14:59:56 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1isT6K-00047n-LN for pgsql-bugs@lists.postgresql.org; Fri, 17 Jan 2020 14:59:56 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1isT6D-0007xP-TN for pgsql-bugs@lists.postgresql.org; Fri, 17 Jan 2020 14:59:56 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id 00HExghb026772; Fri, 17 Jan 2020 09:59:42 -0500 From: Tom Lane To: Fabien COELHO cc: szx9231@gmail.com, PostgreSQL Bugs Subject: Re: BUG #16216: the result of to_date function with negative year number not same as BC year number In-reply-to: References: <16216-68da08087f3aeb78@postgresql.org> Comments: In-reply-to Fabien COELHO message dated "Fri, 17 Jan 2020 15:17:34 +0100" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <26770.1579273182.1@sss.pgh.pa.us> Date: Fri, 17 Jan 2020 09:59:42 -0500 Message-ID: <26771.1579273182@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Fabien COELHO writes: >> postgres=# select to_date('-120', 'yyyy'); >> to_date >> --------------- >> 0121-01-01 BC >> (1 row) > ISTM that the documentation does not say that -120 is supported as meaning > BC. Indeed it does not. The behavior is "correct" in terms of our internals, as you say, but I'm a bit distressed to find that we're exposing the internals this much. If we do anything about this, my vote would be to throw an error for zero or negative year field. OTOH, the point of to_date is mostly not to throw an error, so maybe we should leave it be. > BTW I found another oddity while trying strange date patterns: > sql> SELECT DATE 'Jan 1, 0001 AD'; > # 0001-01-01 > But: > sql> SELECT DATE 'Jan 1, 1 AD'; > # 2001-01-01 # WT*? I'm pretty sure that's intentional; if you specify two or fewer year digits, a year between 1970 and 2069 is presumed to be meant. regards, tom lane