SQLSTATE 22008Severity lowLab verified

Incident brief

Datetime field overflow

A date/time value was well-formed text, but named a value that doesn't exist on the calendar or falls outside PostgreSQL's supported range.

Reproduced on PostgreSQL 16.14Verified 2026-07-16 (Docker lab, PostgreSQL 16.14)Reviewed by Verified against PostgreSQL 16.14 in an isolated lab environment

In 10 seconds

What
Datetime field overflow
What triggers it
Cast a well-formed date string that names an impossible calendar day, such as February 30th.
The fix
Validate day-of-month against the actual month and leap-year rules before sending it to PostgreSQL, or just let PostgreSQL reject it and handle the error.
Proof
Reproduced on PostgreSQL 16.14 → Casting a well-formed but nonexistent calendar date (February 30th) was rejected with SQLSTATE 22008. The session was unaffected afterward.

The fix

What to do right now

The immediate, application-level response to this error.

  • Validate day-of-month against the actual month and leap-year rules before sending it to PostgreSQL, or just let PostgreSQL reject it and handle the error.
  • Don't assume a regex/format check is enough — see the premium test for a second, unrelated way this same SQLSTATE is triggered.
  • For application-computed dates (e.g. 'add N months'), check the result is still inside PostgreSQL's supported date range (4713 BC to 5874897 AD).
Fix — SQL
SELECT '2024-02-29'::date; -- 2024 is a leap year

Related & next steps

Follow the thread

Everything this error touches — jump straight to the sibling error, term, runbook, or parameter.

Verification

PG 16.14
Last verified
2026-07-16 (Docker lab, PostgreSQL 16.14)
Reviewed by
Verified against PostgreSQL 16.14 in an isolated lab environment
Audit status
reviewed