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 1x278p-005ase-14 for pgsql-bugs@arkaria.postgresql.org; Thu, 03 Sep 2026 13:06:07 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1x278o-000duh-1B for pgsql-bugs@arkaria.postgresql.org; Thu, 03 Sep 2026 13:06:06 +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 1x21E2-00GJeq-1g for pgsql-bugs@lists.postgresql.org; Thu, 03 Sep 2026 06:47:06 +0000 Received: from mahout.postgresql.org ([2001:4800:3e1:1::227]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1x21E0-00000003lR1-3gr4 for pgsql-bugs@lists.postgresql.org; Thu, 03 Sep 2026 06:47:05 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=postgresql.org; s=20171124; h=Message-ID:Date:Reply-To:Cc:From:To:Subject: Content-Transfer-Encoding:MIME-Version:Content-Type:Sender:Content-ID: Content-Description:In-Reply-To:References; bh=ledCkw7eRf0jT25nBOYR18yPViSjPkk/FA6iAhNiSRo=; b=TjVisMoHCKNHzYtpTorYztt8T1 YMDjvBd9WyGKZz1grI7fieA4qjiuYh+nbs0u7dxR8l/9smGdWd/w87UKCaUYLSXrRpKm/i0x7GUDZ M+dH7xQWOzUnViTVSYkV2KPdKqSvVfGTq+Xt8rfS1h2V76eYi6K34CHlNiwOEJHhgIEazDmDNqhHV cXeIx3Xt6Ldq4pJFzJpX93+qm2zPK0JEhsy5UU6b+ObT7F6BIueDhO5dF6PgBcJI2+j2S9DLkhCP2 js7p4GUj2bWNjYSjeW8zyFX9VSi0ArCPWgeXw7TRU4amjCOXwA495oYJKahBrEpeFPH3CYCM4GCJR 48BdrKRA==; Received: from wrigleys.postgresql.org ([2a02:16a8:dc51::60]) by mahout.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1x21E0-00BOdV-28 for pgsql-bugs@lists.postgresql.org; Thu, 03 Sep 2026 06:47:04 +0000 Received: from localhost ([127.0.0.1] helo=wrigleys.postgresql.org) by wrigleys.postgresql.org with esmtp (Exim 4.98.2) (envelope-from ) id 1x21Dz-0000000D7rO-2iqY for pgsql-bugs@lists.postgresql.org; Thu, 03 Sep 2026 06:47:03 +0000 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Subject: BUG #19651: to_date()/to_timestamp() silently accept out-of-range values for SSSSS, RM, IW and ID format fields To: pgsql-bugs@lists.postgresql.org From: PG Bug reporting form Cc: 303677365@qq.com Reply-To: 303677365@qq.com, pgsql-bugs@lists.postgresql.org Date: Thu, 03 Sep 2026 06:46:30 +0000 Message-ID: <19651-fdc8457e83a39ba1@postgresql.org> X-Auto-Response-Suppress: All Auto-Submitted: auto-generated List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk The following bug has been logged on the website: Bug reference: 19651 Logged by: chunling qin Email address: 303677365@qq.com PostgreSQL version: 18.6 Operating system: x86_64 Description: =20 Four to_date()/to_timestamp() format fields whose documented value ranges are narrow accept out-of-range input silently and produce a wrong date, while sister fields in the same domain raise errors for the same kind of input: 1. SSSSS (seconds since midnight, documented 0-86399) =E2=80=94 negative va= lue silently negated: SELECT to_timestamp('2024-01-01 -1', 'YYYY-MM-DD SSSSS'); -- 2024-01-01 00:00:01+00 (-1 second becomes +1 second) 2. RM (Roman month numeral, documented I..XII) =E2=80=94 out-of-range numer= al accepted: SELECT to_date('2024 XIII', 'YYYY RM'); -- 2024-12-01 (XIII parsed as month 12) 3. IW (ISO week, documented 01-53) =E2=80=94 values 54-99 accepted, silently spilling into the following year. The sister field WW validates the same value correctly: SELECT to_date('2024 54', 'IYYY IW'); -- 2025-01-06 (no error) SELECT to_date('2024 99', 'IYYY IW'); -- 2025-11-17 (no error) SELECT to_date('2024 54', 'YYYY WW'); -- ERROR: date/time field value out of range: "2024 54" 4. ID (ISO day of week, documented 1-7) =E2=80=94 both 0 and 8 accepted, ea= ch mapped to Sunday: SELECT to_date('2024 01 8', 'IYYY IW ID'); -- 2024-01-07 (should be an error) SELECT to_date('2024 01 0', 'IYYY IW ID'); -- 2024-01-07 (same Sunday result as 7) Expected behavior Each field should raise date/time field value out of range for input outside its documented domain, consistently with how DDD (367+), WW (54+), MM (13+), DD (32+) and others already behave.