SQLSTATE 22008 ERROR Class 22: Data Exception

datetime_field_overflow timestamp out of range — 22008

PostgreSQL error "timestamp out of range" (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 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

  1. Check units when converting epochs: to_timestamp(ms / 1000.0).
  2. Bound or validate values before arithmetic.
  3. Use timestamptz consistently and sanity-check extreme dates.

Related & next steps

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

Was this helpful?