Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1wGFtP-0062bU-0u for pgsql-bugs@arkaria.postgresql.org; Fri, 24 Apr 2026 12:44:24 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1wGFtO-006VxE-1g for pgsql-bugs@arkaria.postgresql.org; Fri, 24 Apr 2026 12:44:22 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1wGFtO-006Vwx-09 for pgsql-bugs@lists.postgresql.org; Fri, 24 Apr 2026 12:44:22 +0000 Received: from smtp.outgoing.loopia.se ([93.188.3.37]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1wGFtK-00000002Zo1-2nfS for pgsql-bugs@lists.postgresql.org; Fri, 24 Apr 2026 12:44:21 +0000 Received: from s807.loopia.se (localhost [127.0.0.1]) by s807.loopia.se (Postfix) with ESMTP id 60DA95B0BB4 for ; Fri, 24 Apr 2026 14:44:15 +0200 (CEST) Received: from s979.loopia.se (unknown [172.22.191.5]) by s807.loopia.se (Postfix) with ESMTP id 4B5E95B179B; Fri, 24 Apr 2026 14:44:15 +0200 (CEST) Received: from localhost (unknown [172.22.191.5]) by s979.loopia.se (Postfix) with ESMTP id 479DF10BC419; Fri, 24 Apr 2026 14:44:15 +0200 (CEST) X-Virus-Scanned: amavis at amavis.loopia.se X-Spam-Flag: NO X-Spam-Score: -1.2 X-Spam-Level: X-Spam-Status: No, score=-1.2 tagged_above=-999 required=6.2 tests=[ALL_TRUSTED=-1, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1] autolearn=disabled Authentication-Results: s898.loopia.se (amavis); dkim=pass (2048-bit key) header.d=yesql.se Received: from s980.loopia.se ([172.22.191.6]) by localhost (s898.loopia.se [172.22.190.17]) (amavis, port 10024) with LMTP id AVbP8lzYsLyQ; Fri, 24 Apr 2026 14:44:14 +0200 (CEST) X-Loopia-Auth: user X-Loopia-User: daniel@yesql.se X-Loopia-Originating-IP: 89.255.232.236 Received: from smtpclient.apple (customer-89-255-232-236.stosn.net [89.255.232.236]) (Authenticated sender: daniel@yesql.se) by s980.loopia.se (Postfix) with ESMTPSA id 92EE12201663; Fri, 24 Apr 2026 14:44:14 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yesql.se; s=loopiadkim1707475645; t=1777034654; bh=4T0jzr9ZX0tWaBkcRDJ4Kc4YdPQgGIAzL9920vaGXoY=; h=From:Subject:Date:In-Reply-To:Cc:To:References; b=RR9XMmpouUAA5FLZGpHPUwfWG6rAbXBXVDqS8IE2irLBz+QtG3Nqa2ah/w1Kt9VvG /4DJYap/pBJfOUC9BfIzrHsbIPQtUi45Df7LkrpWbIMNmUHKDW2dl8pngvqW6SPCDp 3wLvi0B8PEtxe96ujmQ07VOsqhSSZ5V/1tEvE1eDS6AmiZFVkkN7Bf7AU4qZfDFRU0 HhGNzlXNfk33X/IdKC+DqgC7WFBmyGTaGkvPpdU1wYcXTwL9/jv3elcdGNqNoqKeaJ 5VGeCK5BRsJGMKYIuzqKzNkho/fNF5XC+oKrIcLctILFVaIg3VZEtmHcXvnFzW6sdb 98yvB+rxqXDxg== From: Daniel Gustafsson Message-Id: <1B595919-2596-4CB3-BC39-DDCCB9876E56@yesql.se> Content-Type: multipart/mixed; boundary="Apple-Mail=_9E47FC16-330D-4840-9FC4-EEE4E248FA33" Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3776.700.51.11.2\)) Subject: Re: to_date()/to_timestamp() silently accept month=0 and day=0 Date: Fri, 24 Apr 2026 14:44:04 +0200 In-Reply-To: Cc: Michael Paquier , Tom Lane , pgsql-bugs@lists.postgresql.org To: Ayush Tiwari References: <1444609.1776958814@sss.pgh.pa.us> X-Mailer: Apple Mail (2.3776.700.51.11.2) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --Apple-Mail=_9E47FC16-330D-4840-9FC4-EEE4E248FA33 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=us-ascii > On 24 Apr 2026, at 11:13, Ayush Tiwari = wrote: > Attached patch, please review. LGTM for the most part, I don't really think we need to use both to_date = and to_timestamp though, we can save a few cycles there. I rewrote the = comments to match the rest of the file, and moved to where to where we test for year = 0000 since it seems like a better place. Also took the liberty to use year = 100 in one of the testcase, while the year is superfluous for the test in = question, year 100 was previously untested so this will increase test coverage for = free. -- Daniel Gustafsson --Apple-Mail=_9E47FC16-330D-4840-9FC4-EEE4E248FA33 Content-Disposition: attachment; filename=v2-0001-Add-regression-tests-for-zero-month-day-handling-.patch Content-Type: application/octet-stream; x-unix-mode=0644; name="v2-0001-Add-regression-tests-for-zero-month-day-handling-.patch" Content-Transfer-Encoding: quoted-printable =46rom=20dc0b7a09e0e02c587ba594d5af741c14186969e1=20Mon=20Sep=2017=20= 00:00:00=202001=0AFrom:=20Daniel=20Gustafsson=20= =0ADate:=20Fri,=2024=20Apr=202026=2014:37:05=20= +0200=0ASubject:=20[PATCH=20v2]=20Add=20regression=20tests=20for=20zero=20= month/day=20handling=20in=0A=20to_date=0A=0AZero=20values=20for=20month=20= and=20day=20fields=20in=20to_date()=20(and=20to_timestamp())=0Aformat=20= strings=20are=20intentionally=20treated=20as=20missing=20data=20and=20= default=0Ato=201=20(January=20/=20day-of-month=201),=20matching=20the=20= ZERO_tm()=20initialization=0Ain=20formatting.c.=20=20Add=20tests=20= documenting=20this=20long-standing=20behavior.=0A=0AAuthor:=20Ayush=20= Tiwari=20=0ADiscussion:=20= https://postgr.es/m/CAJTYsWWNfF+hMpbsTDF8NMr+AuqoDfNxR=3DoHUZm7xqGP+dJ9rA@= mail.gmail.com=0A---=0A=20src/test/regress/expected/horology.out=20|=20= 25=20+++++++++++++++++++++++++=0A=20src/test/regress/sql/horology.sql=20=20= =20=20=20=20|=20=205=20+++++=0A=202=20files=20changed,=2030=20= insertions(+)=0A=0Adiff=20--git=20= a/src/test/regress/expected/horology.out=20= b/src/test/regress/expected/horology.out=0Aindex=20= 32cf62b6741..6c8f4b1c19d=20100644=0A---=20= a/src/test/regress/expected/horology.out=0A+++=20= b/src/test/regress/expected/horology.out=0A@@=20-3818,6=20+3818,31=20@@=20= SELECT=20to_date('0000-02-01','YYYY-MM-DD');=20=20--=20allowed,=20though=20= it=20shouldn't=20be=0A=20=2002-01-0001=20BC=0A=20(1=20row)=0A=20=0A+--=20= Zero=20month/day=20values=20are=20treated=20as=20missing=20data=20and=20= default=20to=201=0A+SELECT=20to_date('2024-00-15',=20'YYYY-MM-DD');=20=20= --=20ok,=200=20->=20January=0A+=20=20to_date=20=20=20=0A+------------=0A= +=2001-15-2024=0A+(1=20row)=0A+=0A+SELECT=20to_date('2024-01-00',=20= 'YYYY-MM-DD');=20=20--=20ok,=200=20->=201'st=0A+=20=20to_date=20=20=20=0A= +------------=0A+=2001-01-2024=0A+(1=20row)=0A+=0A+SELECT=20= to_date('100-00-00',=20'YYY-MM-DD');=20=20--=20ok,=200/0=20->=20Jan=20= 1st,=20year=20100=20->=202100=0A+=20=20to_date=20=20=20=0A+------------=0A= +=2001-01-2100=0A+(1=20row)=0A+=0A+SELECT=20to_date('100',=20'YYY');=20= --=20ok,=20equivalent=20to=20above=0A+=20=20to_date=20=20=20=0A= +------------=0A+=2001-01-2100=0A+(1=20row)=0A+=0A=20SELECT=20= to_date('100000000',=20'CC');=0A=20ERROR:=20=20date/time=20field=20value=20= out=20of=20range:=20"100000000"=0A=20SELECT=20to_date('-100000000',=20= 'CC');=0Adiff=20--git=20a/src/test/regress/sql/horology.sql=20= b/src/test/regress/sql/horology.sql=0Aindex=208978249a5dc..ec4ef6814a5=20= 100644=0A---=20a/src/test/regress/sql/horology.sql=0A+++=20= b/src/test/regress/sql/horology.sql=0A@@=20-670,6=20+670,11=20@@=20= SELECT=20to_date('2016=20365',=20'YYYY=20DDD');=20=20--=20ok=0A=20SELECT=20= to_date('2016=20366',=20'YYYY=20DDD');=20=20--=20ok=0A=20SELECT=20= to_date('2016=20367',=20'YYYY=20DDD');=0A=20SELECT=20= to_date('0000-02-01','YYYY-MM-DD');=20=20--=20allowed,=20though=20it=20= shouldn't=20be=0A+--=20Zero=20month/day=20values=20are=20treated=20as=20= missing=20data=20and=20default=20to=201=0A+SELECT=20= to_date('2024-00-15',=20'YYYY-MM-DD');=20=20--=20ok,=200=20->=20January=0A= +SELECT=20to_date('2024-01-00',=20'YYYY-MM-DD');=20=20--=20ok,=200=20->=20= 1'st=0A+SELECT=20to_date('100-00-00',=20'YYY-MM-DD');=20=20--=20ok,=20= 0/0=20->=20Jan=201st,=20year=20100=20->=202100=0A+SELECT=20= to_date('100',=20'YYY');=20--=20ok,=20equivalent=20to=20above=0A=20= SELECT=20to_date('100000000',=20'CC');=0A=20SELECT=20= to_date('-100000000',=20'CC');=0A=20SELECT=20to_date('-2147483648=2001',=20= 'CC=20YY');=0A--=20=0A2.39.3=20(Apple=20Git-146)=0A=0A= --Apple-Mail=_9E47FC16-330D-4840-9FC4-EEE4E248FA33--