22015
PostgreSQLERRORNotableData ExceptionHIGH confidence
interval field overflow
What this means
SQLSTATE 22015 is raised when an interval value has a field that exceeds the maximum representable value, or when interval arithmetic produces a result too large to store in the interval type.
Why it happens
- 1Computing an interval whose microsecond, second, minute, hour, day, month, or year component overflows the internal representation
- 2Casting an extremely large numeric value to interval
How to reproduce
Casting an overflowing number to an interval.
trigger — this will error
trigger — this will error
SELECT (1e18)::bigint * interval '1 second';
expected output
ERROR: interval field value out of range
Fix
Reduce the magnitude of interval inputs
WHEN When computing very large intervals.
Why this works
Break the interval into smaller components or normalise the input value to fit within the interval type limits (about +/- 178,000,000 years).
Sources
Official documentation ↗
Class 22 — Data Exception
Content generated with AI assistance and reviewed for accuracy. Found an error? hello@errcodes.dev