PostgreSQL error code
PostgreSQL error 22015
22015 is the SQLSTATE PostgreSQL reports for interval field overflow, in class 22, Data Exception.
| SQLSTATE | 22015 |
|---|---|
| Condition name | interval_field_overflow |
| Class | 22 — Data Exception |
Reproduce it, then fix it
Each field of an interval is a 32-bit integer, so it tops out at 2,147,483,647 days. A number that large is almost always a millisecond timestamp read as days; to_timestamp takes seconds. Run the broken query to see the error, then switch to the fixed one. Edit either freely; every run is rolled back.
SELECT now() + (1716800000000 || ' days')::interval;
SELECT to_timestamp(1716800000000 / 1000.0);