Diagnostic Queries
Symptoms
A value being converted to timestamp/timestamptz is not a recognized date-time. PostgreSQL raises SQLSTATE 22007 (invalid_datetime_format) and quotes the bad value.
- Common with ambiguous or non-ISO date formats.
- Empty strings and locale-specific formats are frequent culprits.
- The current
DateStylesetting affects what is accepted.
What the server log shows
ERROR: invalid input syntax for type timestamp: "2026-13-40 99:99"
Why PostgreSQL raises this — what the manual says
Section 8.5.1 Date/Time Input:
“Date and time input is accepted in almost any reasonable format”
The timestamp input parser interprets the string according to DateStyle and field ranges. Out-of-range fields, unparseable text, or empty strings cannot form a valid timestamp and fail with 22007.
Common causes
- Out-of-range fields (month 13, hour 99).
- Empty string for a missing timestamp.
- Ambiguous day/month order conflicting with
DateStyle. - Locale or custom formats the parser does not recognize.
How to fix it
- Send ISO 8601 (
YYYY-MM-DD HH:MI:SS) to avoid ambiguity. - Parse non-standard formats with
to_timestamp(text, format). - Convert empty strings to NULL; set
DateStyleappropriately for the session.
Related & next steps
Reference: PostgreSQL 18 Section 8.5 “Date/Time Types”.
Thanks — noted. This helps keep the database accurate.