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-005asd-1C 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-19 for pgsql-bugs@arkaria.postgresql.org; Thu, 03 Sep 2026 13:06:06 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1x21D8-00GJba-39 for pgsql-bugs@lists.postgresql.org; Thu, 03 Sep 2026 06:46:10 +0000 Received: from mahout.postgresql.org ([2001:4800:3e1:1::227]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1x21D3-00000002gAy-2gc0 for pgsql-bugs@lists.postgresql.org; Thu, 03 Sep 2026 06:46:10 +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=Clfz+v7NbhGXBCGSvvs9VwQz2tiyxxYT8v4t6hbTFdQ=; b=BMRmSTkn4FSd7bE3Tg9BI/BMnM JymkRjHDaMw08aqMtPdrZVvr2sj7eJaBnec3+Zag3h0JqwPikx5by313aLjFB6vmiMV2+vuW1CxDs 9y0CT/1xDkq1zhMGoFdE7IDJxpK/f66y7p4dd0D7eLeuSaQNTCtDEQSh/QlL93meCm36L8eq+xrWa 4ZsTyEqZ7GO2lEvwOhpCA0hKB5KC+1a8edpSBkZbJsFtwe0L8EzvK1Zfw1YASfC1psjWoZ/qYgHrj 4amh0g8suPnNObK490SWHPOjV5y0T2hzeot93VAb4/1VVPwt6p0e+AFir6Xv3GIMwN9zVF5jjBbOD SOUx3wxw==; 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 1x21D2-00BOcW-1P for pgsql-bugs@lists.postgresql.org; Thu, 03 Sep 2026 06:46: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 1x21D1-0000000D7nJ-1iZY for pgsql-bugs@lists.postgresql.org; Thu, 03 Sep 2026 06:46:03 +0000 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Subject: BUG #19650: to_date()/to_timestamp() silently truncate 4+-digit day-of-year input to the first three digits 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:45:25 +0000 Message-ID: <19650-d7ea430084cdc44a@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: 19650 Logged by: chunling qin Email address: 303677365@qq.com PostgreSQL version: 18.6 Operating system: x86_64 Description: =20 The documentation states that DDD (day of year) accepts values 001-366 and IDDD (ISO day of year) 001-371, and out-of-range values raise an error. That check works for 3-digit input, but for input of 4 or more digits the parser silently keeps only the first three digits and treats them as a valid day number: SELECT to_date('2024 1000', 'YYYY DDDD'); -- 2024-04-09 (parsed as day 100 =E2=80=94 the first three digits) SELECT to_date('2024 1234', 'YYYY DDDD'); -- 2024-05-02 (parsed as day 123) SELECT to_date('2024 10000', 'YYYY DDDD'); -- 2024-04-09 (5-digit input, still day 100) SELECT to_date('2024 999', 'IYYY IDDD'); -- 2026-09-25 (IDDD 999 silently accepted; an ISO year has at most 371 days) ``` hunt@(null)=3D# SELECT to_date('2024 1000', 'YYYY DDDD'); -- 2024-04-09 (parsed as day 100 =E2=80=94 the first three digits) SELECT to_date('2024 1234', 'YYYY DDDD'); -- 2024-05-02 (parsed as day 123) SELECT to_date('2024 10000', 'YYYY DDDD'); -- 2024-04-09 (5-digit input, still day 100) SELECT to_date('2024 999', 'IYYY IDDD'); -- 2026-09-25 (IDDD 999 silently accepted; an ISO year has at most 371 days) to_date ------------ 2024-04-09 (1 row) to_date ------------ 2024-05-02 (1 row) to_date ------------ 2024-04-09 (1 row) to_date ------------ 2026-09-25 (1 row) hunt@(null)=3D# SELECT to_date('2024 367', 'YYYY DDD'); -- ERROR: date/time field value out of range: "2024 367" ERROR: date/time field value out of range: "2024 367" ```