SQLSTATE 22008 ERROR Class 22: Data Exception

datetime_field_overflow date out of range for type … — 22008

PostgreSQL error "date out of range for type …" (SQLSTATE 22008): what it means, common causes, and how to fix it.

PG 12, 13, 14, 15, 16, 17, 18 Official docs
Last reviewed May 2025 Grounded in source

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

  1. Validate/clamp date values before insert.
  2. Use a type with a wider range if appropriate (e.g. timestamptz vs narrower types).
  3. Replace sentinel/placeholder dates with NULL or valid values.

Related & next steps

Reference: PostgreSQL 18 Section 8.5 “Date/Time Types”.

Was this helpful?