Bad canonicalization for dateranges with 'infinity' bounds

From: Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at>
To: pgsql-hackers(at)lists(dot)postgresql(dot)org
Subject: Bad canonicalization for dateranges with 'infinity' bounds
Date: 2019-05-02 12:40:52
Message-ID: 77f24ea19ab802bc9bc60ddbb8977ee2d646aec1.camel@cybertec.at
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

https://www.postgresql.org/docs/current/rangetypes.html#RANGETYPES-INFINITE has:

Also, some element types have a notion of “infinity”, but that is just
another value so far as the range type mechanisms are concerned.
For example, in timestamp ranges, [today,] means the same thing as [today,).
But [today,infinity] means something different from [today,infinity) —
the latter excludes the special timestamp value infinity.

This does not work as expected for ranges with discrete base types,
notably daterange:

test=> SELECT '[2000-01-01,infinity]'::daterange;
daterange
-----------------------
[2000-01-01,infinity)
(1 row)

test=> SELECT '(-infinity,2000-01-01)'::daterange;
daterange
------------------------
[-infinity,2000-01-01)
(1 row)

This is because "daterange_canonical" makes no difference for 'infinity',
and adding one to infinity does not change the value.

I propose the attached patch which fixes the problem.

Yours,
Laurenz Albe

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Laurenz Albe 2019-05-02 12:49:23 Re: Bad canonicalization for dateranges with 'infinity' bounds
Previous Message Tomas Vondra 2019-05-02 12:35:45 Re: walsender vs. XLogBackgroundFlush during shutdown