Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit955089d

Browse files
committed
Fix daterange canonicalization for +/- infinity.
The values 'infinity' and '-infinity' are a part of the DATE typeitself, so a bound of the date 'infinity' is not the same as anunbounded/infinite range. However, it is still wrong to try tocanonicalize such values, because adding or subtracting one has noeffect. Fix by treating 'infinity' and '-infinity' the same asunbounded ranges for the purposes of canonicalization (but not otherpurposes).Backpatch to all versions because it is inconsistent with thedocumented behavior. Note that this could be an incompatibility forapplications relying on the behavior contrary to the documentation.Author: Laurenz AlbeReviewed-by: Thomas MunroDiscussion:https://postgr.es/m/77f24ea19ab802bc9bc60ddbb8977ee2d646aec1.camel%40cybertec.atBackpatch-through: 9.4
1 parent53256e8 commit955089d

File tree

3 files changed

+30
-2
lines changed

3 files changed

+30
-2
lines changed

‎src/backend/utils/adt/rangetypes.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1366,13 +1366,13 @@ daterange_canonical(PG_FUNCTION_ARGS)
13661366
if (empty)
13671367
PG_RETURN_RANGE(r);
13681368

1369-
if (!lower.infinite&& !lower.inclusive)
1369+
if (!lower.infinite&& !DATE_NOT_FINITE(lower.val)&& !lower.inclusive)
13701370
{
13711371
lower.val=DirectFunctionCall2(date_pli,lower.val,Int32GetDatum(1));
13721372
lower.inclusive= true;
13731373
}
13741374

1375-
if (!upper.infinite&&upper.inclusive)
1375+
if (!upper.infinite&&!DATE_NOT_FINITE(upper.val)&&upper.inclusive)
13761376
{
13771377
upper.val=DirectFunctionCall2(date_pli,upper.val,Int32GetDatum(1));
13781378
upper.inclusive= false;

‎src/test/regress/expected/rangetypes.out

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -652,6 +652,30 @@ select daterange('2000-01-10'::date, '2000-01-11'::date, '(]');
652652
[01-11-2000,01-12-2000)
653653
(1 row)
654654

655+
select daterange('-infinity'::date, '2000-01-01'::date, '()');
656+
daterange
657+
------------------------
658+
(-infinity,01-01-2000)
659+
(1 row)
660+
661+
select daterange('-infinity'::date, '2000-01-01'::date, '[)');
662+
daterange
663+
------------------------
664+
[-infinity,01-01-2000)
665+
(1 row)
666+
667+
select daterange('2000-01-01'::date, 'infinity'::date, '[)');
668+
daterange
669+
-----------------------
670+
[01-01-2000,infinity)
671+
(1 row)
672+
673+
select daterange('2000-01-01'::date, 'infinity'::date, '[]');
674+
daterange
675+
-----------------------
676+
[01-01-2000,infinity]
677+
(1 row)
678+
655679
-- test GiST index that's been built incrementally
656680
create table test_range_gist(ir int4range);
657681
create index test_range_gist_idx on test_range_gist using gist (ir);

‎src/test/regress/sql/rangetypes.sql

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,10 @@ select daterange('2000-01-10'::date, '2000-01-20'::date, '(]');
165165
select daterange('2000-01-10'::date,'2000-01-20'::date,'()');
166166
select daterange('2000-01-10'::date,'2000-01-11'::date,'()');
167167
select daterange('2000-01-10'::date,'2000-01-11'::date,'(]');
168+
select daterange('-infinity'::date,'2000-01-01'::date,'()');
169+
select daterange('-infinity'::date,'2000-01-01'::date,'[)');
170+
select daterange('2000-01-01'::date,'infinity'::date,'[)');
171+
select daterange('2000-01-01'::date,'infinity'::date,'[]');
168172

169173
-- test GiST index that's been built incrementally
170174
createtabletest_range_gist(ir int4range);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp