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

Commit2be3554

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 parent8474656 commit2be3554

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
@@ -1338,13 +1338,13 @@ daterange_canonical(PG_FUNCTION_ARGS)
13381338
if (empty)
13391339
PG_RETURN_RANGE(r);
13401340

1341-
if (!lower.infinite&& !lower.inclusive)
1341+
if (!lower.infinite&& !DATE_NOT_FINITE(lower.val)&& !lower.inclusive)
13421342
{
13431343
lower.val=DirectFunctionCall2(date_pli,lower.val,Int32GetDatum(1));
13441344
lower.inclusive= true;
13451345
}
13461346

1347-
if (!upper.infinite&&upper.inclusive)
1347+
if (!upper.infinite&&!DATE_NOT_FINITE(upper.val)&&upper.inclusive)
13481348
{
13491349
upper.val=DirectFunctionCall2(date_pli,upper.val,Int32GetDatum(1));
13501350
upper.inclusive= false;

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

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

637+
select daterange('-infinity'::date, '2000-01-01'::date, '()');
638+
daterange
639+
------------------------
640+
(-infinity,01-01-2000)
641+
(1 row)
642+
643+
select daterange('-infinity'::date, '2000-01-01'::date, '[)');
644+
daterange
645+
------------------------
646+
[-infinity,01-01-2000)
647+
(1 row)
648+
649+
select daterange('2000-01-01'::date, 'infinity'::date, '[)');
650+
daterange
651+
-----------------------
652+
[01-01-2000,infinity)
653+
(1 row)
654+
655+
select daterange('2000-01-01'::date, 'infinity'::date, '[]');
656+
daterange
657+
-----------------------
658+
[01-01-2000,infinity]
659+
(1 row)
660+
637661
-- test GiST index that's been built incrementally
638662
create table test_range_gist(ir int4range);
639663
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
@@ -161,6 +161,10 @@ select daterange('2000-01-10'::date, '2000-01-20'::date, '(]');
161161
select daterange('2000-01-10'::date,'2000-01-20'::date,'()');
162162
select daterange('2000-01-10'::date,'2000-01-11'::date,'()');
163163
select daterange('2000-01-10'::date,'2000-01-11'::date,'(]');
164+
select daterange('-infinity'::date,'2000-01-01'::date,'()');
165+
select daterange('-infinity'::date,'2000-01-01'::date,'[)');
166+
select daterange('2000-01-01'::date,'infinity'::date,'[)');
167+
select daterange('2000-01-01'::date,'infinity'::date,'[]');
164168

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

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp