Diagnostic Queries
Symptoms
A date/time value fell outside the range a given type can represent. PostgreSQL raises SQLSTATE 22008 (datetime_field_overflow).
- The value is beyond the type’s supported min/max.
- Common with year-zero, far-future, or pre-4713 BC dates.
- May surface during casts or arithmetic.
What the server log shows
ERROR: date out of range for type timestamp
Why PostgreSQL raises this — what the manual says
As Section 8.5 Date/Time Types (Table 8.9) explains:
Per Table 8.9, each date/time type has a fixed low and high value (for example date spans 4713 BC to 5874897 AD); a value beyond what the target type can store is reported as out of range.
Each temporal type stores values within a fixed range (for example, timestamp spans 4713 BC to 294276 AD). A value or computation outside that range cannot be represented and is rejected with 22008.
Common causes
- Date arithmetic overflowing the type’s range.
- Importing out-of-range or sentinel dates (e.g.
9999-99-99). - Casting a wide type into a narrower one.
How to fix it
- Validate/clamp date values before insert.
- Use a type with a wider range if appropriate (e.g.
timestamptzvs narrower types). - Replace sentinel/placeholder dates with NULL or valid values.
Related & next steps
Reference: PostgreSQL 18 Section 8.5 “Date/Time Types”.
Thanks — noted. This helps keep the database accurate.