Diagnostic Queries
Symptoms
A timestamp value or computation falls outside the supported range of the timestamp type. PostgreSQL raises SQLSTATE 22008 (datetime_field_overflow).
- Timestamps support roughly 4713 BC to 294276 AD.
- Often from arithmetic adding huge intervals, or epoch conversions with bad units.
- Can appear when casting very large integers via
to_timestamp.
What the server log shows
ERROR: timestamp out of range
Why PostgreSQL raises this — what the manual says
As Section 8.5 Date/Time Types (Table 8.9) explains:
Per Table 8.9, the timestamp types can represent values only from 4713 BC to 294276 AD at microsecond resolution; a value or computation outside that supported range raises this error.
Timestamps are stored as microseconds from an epoch within a finite range. A value or arithmetic result beyond the representable range cannot be stored and fails with 22008.
Common causes
- Adding very large intervals to a timestamp.
to_timestamp()on a value in the wrong unit (milliseconds vs seconds).- Corrupt or extreme source data during import.
How to fix it
- Check units when converting epochs:
to_timestamp(ms / 1000.0). - Bound or validate values before arithmetic.
- Use
timestamptzconsistently and sanity-check extreme dates.
Related & next steps
Reference: PostgreSQL 18 Section 8.5 “Date/Time Types”.
Thanks — noted. This helps keep the database accurate.