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 1noHju-0003Ve-Dr for pgsql-general@arkaria.postgresql.org; Tue, 10 May 2022 04:44:50 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1noHjt-0006pn-9g for pgsql-general@arkaria.postgresql.org; Tue, 10 May 2022 04:44:49 +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 1noHjs-0006pd-R2 for pgsql-general@lists.postgresql.org; Tue, 10 May 2022 04:44:48 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1noHjp-0007gz-Tk for pgsql-general@lists.postgresql.org; Tue, 10 May 2022 04:44:47 +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 24A4ihN54035766; Tue, 10 May 2022 00:44:44 -0400 From: Tom Lane To: =?UTF-8?B?5q2j5Y2O5ZCV?= cc: pgsql-general@lists.postgresql.org Subject: Re: Question on cast string to date In-reply-to: References: Comments: In-reply-to =?UTF-8?B?5q2j5Y2O5ZCV?= message dated "Tue, 10 May 2022 12:28:35 +0800" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <4035764.1652157883.1@sss.pgh.pa.us> Date: Tue, 10 May 2022 00:44:43 -0400 Message-ID: <4035765.1652157883@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk =?UTF-8?B?5q2j5Y2O5ZCV?= writes: > I test the following SQL in pg15dev (seems same behavior as the > previous version). > select '2020701'::date; > date > ------------ > 0202-07-01 > (1 row) > At the first glance, the result seems quite strange. [ shrug... ] You left out a zero. It's not apparent to me that this answer is wrong. > The question here is: should we throw error for such input? Or what > standard postgres is > using to cast such kind of string? The bar to changing any behavior here is a *lot* higher than you seem to imagine. Having said that, it does appear that we changed this somewhere between 9.3 and 9.4: psql (9.3.25) Type "help" for help. regression=# select '2020701'::date; ERROR: invalid input syntax for type date: "2020701" LINE 1: select '2020701'::date; ^ psql (9.4.26) Type "help" for help. regression=# select '2020701'::date; date ------------ 0202-07-01 (1 row) If you want to pursue this question, you could start by bisecting to find just which commit changed it and why. regards, tom lane