Re: 'infinity'::Interval should be added - Mailing list pgsql-hackers

From Tom Lane
Subject Re: 'infinity'::Interval should be added
Date
Msg-id 5210.1545018533@sss.pgh.pa.us
Whole thread Raw
In response to Re: 'infinity'::Interval should be added  (Robert Haas <robertmhaas@gmail.com>)
Responses Re: 'infinity'::Interval should be added  (Simon Riggs <simon@2ndquadrant.com>)
List pgsql-hackers
Robert Haas <robertmhaas@gmail.com> writes:
> Simon's argument for adding this is that we support 'infinity' for
> timestamp, but is that a good argument for making 'interval' do it,
> given that there are many other types like date for which we don't
> support it?

My feeling is that date is to timestamp as integer is to float.
We have infinities in the latter types but not the former, and
that seems just fine: infinity is one of the additional values
that you get to have with the bigger/more expensive type.
So I don't really feel that the lack of infinity in date is an
argument against whether to provide it for interval.

The positive argument for adding infinity to interval is that
we define operations such as timestamp minus timestamp as
yielding interval.  That's why this has to fail right now:

regression=# select timestamp 'infinity' - timestamp 'now';
ERROR:  cannot subtract infinite timestamps

But if we had infinite intervals then that would have a well
defined result, just as this works:

regression=# select extract(epoch from timestamp 'infinity');
 date_part 
-----------
  Infinity
(1 row)

Of course, there are still cases like timestamp 'infinity' -
timestamp 'infinity' that would need to fail, but that has a
semantic basis rather than "the output type can't represent it".
(No, I don't want to invent an interval equivalent of NaN
to make that not fail.)

[ wanders away wondering why type numeric has NaN but not infinity ]

            regards, tom lane


pgsql-hackers by date:

Previous
From: Robert Haas
Date:
Subject: Re: 'infinity'::Interval should be added
Next
From: Isaac Morland
Date:
Subject: Re: 'infinity'::Interval should be added