Re: 'infinity'::Interval should be added

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Simon Riggs <simon(at)2ndquadrant(dot)com>
Cc: Robert Haas <robertmhaas(at)gmail(dot)com>, Andres Freund <andres(at)anarazel(dot)de>, Isaac Morland <isaac(dot)morland(at)gmail(dot)com>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: 'infinity'::Interval should be added
Date: 2018-12-17 23:00:36
Message-ID: 26022.1545087636@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Simon Riggs <simon(at)2ndquadrant(dot)com> writes:
> I would like to represent 'infinity' as interval->months = INT_MAX

Per the discussion upthread, what we need when creating an
infinite value is to set
month = INT32_MAX, day = INT32_MAX, time = INT64_MAX (for +Infinity)
month = INT32_MIN, day = INT32_MIN, time = INT64_MIN (for -Infinity)
else we'll need to put special-case logic into comparisons.

However, I think that we only need to restrict ordinary values from
not having month equal to INT32_MIN/MAX, that is the full range
of the other two fields can still be available for normal use.
So when *testing* for an infinity, you would only need to look at the
month field.

> Currently
> postgres=# select 'infinity'::timestamp = 'infinity'::timestamp;
> ?column?
> ----------
> t

Correct, we'd need that here too, if only because btree indexes and
sorting require the reflexive axiom to hold.

> so I was thinking that
> postgres=# select 'infinity'::timestamp - 'infinity'::timestamp;
> would be zero rather than an error, for least surprise.

Wrong. This case needs to be undefined, because "infinity"
isn't a specific value. That's what makes it okay to define, say,
infinity plus any finite value as infinity. There are very
well-defined rules about how to calculate with infinity, and
not following them is not the way to proceed here.

tl;dr: we should model it after the behavior of IEEE float infinities,
except we'll want to throw errors where those produce NaNs.

regards, tom lane

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Alexander Korotkov 2018-12-17 23:04:43 Re: gist microvacuum doesn't appear to care about hot standby?
Previous Message Kevin Grittner 2018-12-17 22:54:06 Re: Referential Integrity Checks with Statement-level Triggers