PostgreSQL Error 22008: Datetime Field Overflow
Troubleshoot PostgreSQL SQLSTATE 22008 when date or time fields exceed valid calendar, clock, or timestamp ranges.
On this page
PostgreSQL SQLSTATE 22008 is datetime_field_overflow. It means a date or time field is outside the valid range for the requested value or data type. Read the complete error message to see which value failed; PostgreSQL lists this code in its error-code appendix.
Check the invalid calendar or clock field
Examples of out-of-range values include a thirteenth month, a nonexistent day in a month, or a time later than 24:00:00. PostgreSQL accepts 24:00:00 as the upper bound for time; 25:00:00 is out of range:
SELECT DATE '2026-13-01';
SELECT DATE '2026-02-30';
SELECT TIME '25:00:00';
Correct the source value rather than changing the destination column to a wider type; these values do not represent valid dates or times. PostgreSQL’s date/time type documentation lists the supported ranges and input forms.
Check the target type and parameter value
Confirm whether the destination uses date, time, timestamp, or timestamp with time zone. Inspect the input value before inserting or casting it. For a column, query the declared type:
SELECT column_name, data_type, udt_name
FROM information_schema.columns
WHERE table_schema = 'public'
AND table_name = 'events'
AND column_name = 'occurred_at';
For application requests or imports, validate the source value before conversion. PostgreSQL 16 and later provide pg_input_is_valid and pg_input_error_info:
SELECT raw_timestamp,
(pg_input_error_info(raw_timestamp, 'timestamp with time zone')).message AS input_error
FROM staging_events
WHERE NOT pg_input_is_valid(raw_timestamp, 'timestamp with time zone');
These functions can inspect invalid values without aborting for types whose input functions support soft errors. See PostgreSQL’s data validity checking functions.
Distinguish a bad format from an out-of-range value
- 22008 (
datetime_field_overflow): a date/time field is out of range, such as month 13 or February 30. - 22007 (
invalid_datetime_format): the input does not match an accepted date/time format; see Error 22007. - 22P02 (
invalid_text_representation): a text value cannot be parsed as its requested type; see Error 22P02.
For other SQLSTATE guides, browse PostgreSQL Error Troubleshooting.