Diagnostic Queries
Symptoms
A string could not be parsed as a timestamp. PostgreSQL raises SQLSTATE 22007 (invalid_datetime_format).
- The timestamp text isn’t in a recognized format.
- Common with ambiguous or non-ISO date/time strings.
- Affected by
DateStylefor ambiguous inputs.
What the server log shows
ERROR: invalid input syntax for type timestamp: "2024-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”
Timestamp parsing validates both format and field ranges. Input that isn’t a recognized format, or has out-of-range fields (month 13, etc.), cannot be interpreted, so PostgreSQL reports 22007.
Common causes
- A malformed or out-of-range timestamp string.
- An ambiguous format under the current
DateStyle. - Locale/format mismatch between the app and the server.
How to fix it
- Use ISO 8601:
'2024-01-15 13:45:00'. - Set
DateStyleappropriately for ambiguous inputs. - Use
to_timestamp(text, format)to parse non-standard formats explicitly.
Related & next steps
Reference: PostgreSQL 18 Section 8.5 “Date/Time Types”.
Thanks — noted. This helps keep the database accurate.