| 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 #19651: to_date()/to_timestamp() silently accept out-of-range values for SSSSS, RM, IW and ID format fields |
| Date: | 2026-09-03 06:46:30 |
| Message-ID: | 19651-fdc8457e83a39ba1@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: 19651
Logged by: chunling qin
Email address: 303677365(at)qq(dot)com
PostgreSQL version: 18.6
Operating system: x86_64
Description:
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) — negative value
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) — out-of-range numeral
accepted:
SELECT to_date('2024 XIII', 'YYYY RM');
-- 2024-12-01 (XIII parsed as month 12)
3. IW (ISO week, documented 01-53) — 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) — both 0 and 8 accepted, each 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.
| From | Date | Subject | |
|---|---|---|---|
| Next Message | PG Bug reporting form | 2026-09-03 06:48:00 | BUG #19652: to_number() silently truncates over-length integers |
| Previous Message | PG Bug reporting form | 2026-09-03 06:45:25 | BUG #19650: to_date()/to_timestamp() silently truncate 4+-digit day-of-year input to the first three digits |