postgresqlinfinity

How to declare interval infinity in postgres?


It seems that we can't currently case infinity as an interval.

While trying:
SELECT 'infinity'::interval;`
we get

SQL Error [22007]: ERROR: invalid input syntax for type interval: "infinity"

How could I specify a max value for an interval?

I tried comparing 2 infinity timestamps

SELECT ('-infinity'::timestamp + '1 day'::INTERVAL)::timestamp without time zone at time zone 'UTC' 
- 'infinity'::timestamp  without time zone at time zone 'UTC';  

but now getting

SQL Error [22008]: ERROR: cannot subtract infinite timestamps

Any idea?


Solution

  • Yes, that is true. You cannot represent infinite intervals with the interval data type.