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.98.2) (envelope-from ) id 1x7ICP-00000000HUR-2KN9 for pgsql-docs@arkaria.postgresql.org; Thu, 17 Sep 2026 19:55:13 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.98.2) (envelope-from ) id 1x7ICN-00000005ukU-1Brv for pgsql-docs@arkaria.postgresql.org; Thu, 17 Sep 2026 19:55:11 +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.98.2) (envelope-from ) id 1x7ICN-00000005ukM-01mZ for pgsql-docs@lists.postgresql.org; Thu, 17 Sep 2026 19:55:11 +0000 Received: from momjian.us ([72.94.173.45]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1x7ICK-00000000COR-1fAn for pgsql-docs@lists.postgresql.org; Thu, 17 Sep 2026 19:55:09 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=momjian.us; s=2026010100; h=In-Reply-To:Content-Transfer-Encoding:Content-Type: MIME-Version:References:Message-ID:Subject:To:From:Date:Sender:Reply-To:Cc: Content-ID:Content-Description; bh=JCdYXtV4YNjR2WmxGI2xXcGLp9d9dg+0HdgYQqgTAZ4=; b=gDthvRxBNwjPty0VP8JFOlJR7D TDqdRl9fan6cv7DbyHBtKOqp3xKCNAVOxnkMLZScYLPocCpGMGxzprD+AWwPy1GfNn0D04sdcTxse dS6bB74rHi75ymodft2JLMEMqNZMlitbVrsfcGwySU8t2XsppCRTCjkMNEFrZ6m2bCl//LZWWJVWi 95uDEmsXSpSgxI1uCxWVx6fPu2TCsDVEHjQUHjiZEseyl2L3h25+wqT8ejlwNjnQ6HPM2tZu/Z82E sXc+In2ovr6osn6Q7tG3wrb8ewQvlHM8a3gHM3ZhCxjDyBTXOoUCLI35YZ2WJoNMlcNA7U6+13GFU ZNoohQaw==; Received: from bruce by momjian.us with local (Exim 4.98.2) (envelope-from ) id 1x7ICJ-0000000FZfL-0jrA; Thu, 17 Sep 2026 15:55:07 -0400 Date: Thu, 17 Sep 2026 15:55:07 -0400 From: Bruce Momjian To: kacperkuras@hotmail.com, pgsql-docs@lists.postgresql.org Subject: Re: 8.5.1. Date/Time Input Message-ID: References: <178897820483.2258529.4862563749043725162@wrigleys.postgresql.org> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="zxDU5M0ykofYuQD7" Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <178897820483.2258529.4862563749043725162@wrigleys.postgresql.org> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --zxDU5M0ykofYuQD7 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit On Wed, Sep 9, 2026 at 06:23:24PM +0000, PG Doc comments form wrote: > The following documentation comment has been logged on the website: > > Page: https://www.postgresql.org/docs/18/datatype-datetime.html > Description: > > Section 8.5.1 says date/time input is accepted "in almost any reasonable > format, including ISO 8601". > That holds for years 0001..9999 but not outside them, and I could not find > the limit stated anywhere. > > ISO 8601 writes years outside that range with an explicit sign and more than > four digits. PostgreSQL > rejects those, while holding and printing the very same values in its own > spelling: > > SELECT '10000-01-02'::date; -- 10000-01-02 > SELECT '+10000-01-02'::date; -- ERROR: time zone displacement out of > range: "+10000-01-02" > SELECT '-0001-01-02'::date; -- ERROR: invalid input syntax for type > date: "-0001-01-02" > SELECT '0000-01-02'::date; -- ERROR: date/time field value out of > range: "0000-01-02" > > Per B.1, a token starting with + or - is read as a numeric time zone, and > the first error names that directly. The negative forms fail differently - > as plain syntax rather than as a displacement - so I have not assumed the > same cause for them. Either way, ISO 8601 also counts through a year zero > where PostgreSQL counts BC from one, so ISO -0001 (2 BC) has no ISO spelling > PostgreSQL accepts. > > I ran into this writing a PostgreSQL driver for Kotlin: for such a year, the > ISO 8601 that Kotlin's date library produces is a string PostgreSQL will not > read back — for a date it stores and prints happily. > > Suggested wording — qualify the claim rather than describe the parser, e.g.: > > "...including ISO 8601 (for years 0001-9999; ISO 8601 expanded years > carry an explicit sign, which > is read as a time zone offset — write 10000-01-02 or 0002-01-02 BC > instead), SQL-compatible, > traditional POSTGRES, and others." Good point; for reference: https://en.wikipedia.org/wiki/ISO_8601#Dates I have written the attached patch. -- Bruce Momjian https://momjian.us EDB https://enterprisedb.com Do not let urgent matters crowd out time for investment in the future. --zxDU5M0ykofYuQD7 Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="ISO8601.diff" diff --git a/doc/src/sgml/datatype.sgml b/doc/src/sgml/datatype.sgml index 89985ab7b16..6bc0de06988 100644 --- a/doc/src/sgml/datatype.sgml +++ b/doc/src/sgml/datatype.sgml @@ -1878,7 +1878,10 @@ MINUTE TO SECOND Date and time input is accepted in almost any reasonable format, including ISO 8601, SQL-compatible, - traditional POSTGRES, and others. + traditional POSTGRES, and others. (ISO + 8601 requires years of more than four digits to be preceded by a plus + or minus sign; PostgreSQL supports such + years, but without a sign.) For some formats, ordering of day, month, and year in date input is ambiguous and there is support for specifying the expected ordering of these fields. Set the parameter --zxDU5M0ykofYuQD7--