| From: | PG Bug reporting form <noreply(at)postgresql(dot)org> |
|---|---|
| To: | pgsql-bugs(at)lists(dot)postgresql(dot)org |
| Cc: | 303677365(at)qq(dot)com |
| Subject: | BUG #19650: to_date()/to_timestamp() silently truncate 4+-digit day-of-year input to the first three digits |
| Date: | 2026-09-03 06:45:25 |
| Message-ID: | 19650-d7ea430084cdc44a@postgresql.org |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-bugs |
The following bug has been logged on the website:
Bug reference: 19650
Logged by: chunling qin
Email address: 303677365(at)qq(dot)com
PostgreSQL version: 18.6
Operating system: x86_64
Description:
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 — 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)=# SELECT to_date('2024 1000', 'YYYY DDDD');
-- 2024-04-09 (parsed as day 100 — 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)=# 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"
```
| From | Date | Subject | |
|---|---|---|---|
| Next Message | PG Bug reporting form | 2026-09-03 06:46:30 | BUG #19651: to_date()/to_timestamp() silently accept out-of-range values for SSSSS, RM, IW and ID format fields |
| Previous Message | PG Bug reporting form | 2026-09-03 06:41:49 | BUG #19649: Qual pushdown into GROUP BY subqueries ignores non-equivalence-preserving references to grouping col |