Skip to content

Commit 29904f5

Browse files
committed
Revert "Disallow infinite endpoints in generate_series() for timestamps."
This reverts commit eafdf9d and its back-branch counterparts. Corey Huinker pointed out that we'd discussed this exact change back in 2016 and rejected it, on the grounds that there's at least one usage pattern with LIMIT where an infinite endpoint can usefully be used. Perhaps that argument needs to be re-litigated, but there's no time left before our back-branch releases. To keep our options open, restore the status quo ante; if we do end up deciding to change things, waiting one more quarter won't hurt anything. Rather than just doing a straight revert, I added a new test case demonstrating the usage with LIMIT. That'll at least remind us of the issue if we forget again. Discussion: https://postgr.es/m/3603504.1652068977@sss.pgh.pa.us Discussion: https://postgr.es/m/CADkLM=dzw0Pvdqp5yWKxMd+VmNkAMhG=4ku7GnCZxebWnzmz3Q@mail.gmail.com
1 parent 0abc1a0 commit 29904f5

File tree

5 files changed

+48
-56
lines changed

5 files changed

+48
-56
lines changed

src/backend/utils/adt/timestamp.c

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -5778,20 +5778,6 @@ generate_series_timestamp(PG_FUNCTION_ARGS)
57785778
MemoryContext oldcontext;
57795779
Interval interval_zero;
57805780

5781-
/* Reject infinities in start and stop values */
5782-
if (TIMESTAMP_IS_NOBEGIN(start) ||
5783-
TIMESTAMP_IS_NOEND(start))
5784-
ereport(ERROR,
5785-
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
5786-
errmsg("start value cannot be infinity")));
5787-
if (TIMESTAMP_IS_NOBEGIN(finish) ||
5788-
TIMESTAMP_IS_NOEND(finish))
5789-
ereport(ERROR,
5790-
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
5791-
errmsg("stop value cannot be infinity")));
5792-
5793-
/* Interval doesn't (currently) have infinity, so nothing to check */
5794-
57955781
/* create a function context for cross-call persistence */
57965782
funcctx = SRF_FIRSTCALL_INIT();
57975783

@@ -5872,20 +5858,6 @@ generate_series_timestamptz(PG_FUNCTION_ARGS)
58725858
MemoryContext oldcontext;
58735859
Interval interval_zero;
58745860

5875-
/* Reject infinities in start and stop values */
5876-
if (TIMESTAMP_IS_NOBEGIN(start) ||
5877-
TIMESTAMP_IS_NOEND(start))
5878-
ereport(ERROR,
5879-
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
5880-
errmsg("start value cannot be infinity")));
5881-
if (TIMESTAMP_IS_NOBEGIN(finish) ||
5882-
TIMESTAMP_IS_NOEND(finish))
5883-
ereport(ERROR,
5884-
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
5885-
errmsg("stop value cannot be infinity")));
5886-
5887-
/* Interval doesn't (currently) have infinity, so nothing to check */
5888-
58895861
/* create a function context for cross-call persistence */
58905862
funcctx = SRF_FIRSTCALL_INIT();
58915863

src/test/regress/expected/timestamp.out

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2055,15 +2055,26 @@ select * from generate_series('2020-01-01 00:00'::timestamp,
20552055
Thu Jan 02 03:00:00 2020
20562056
(28 rows)
20572057

2058+
-- the LIMIT should allow this to terminate in a reasonable amount of time
2059+
-- (but that unfortunately doesn't work yet for SELECT * FROM ...)
2060+
select generate_series('2022-01-01 00:00'::timestamp,
2061+
'infinity'::timestamp,
2062+
'1 month'::interval) limit 10;
2063+
generate_series
2064+
--------------------------
2065+
Sat Jan 01 00:00:00 2022
2066+
Tue Feb 01 00:00:00 2022
2067+
Tue Mar 01 00:00:00 2022
2068+
Fri Apr 01 00:00:00 2022
2069+
Sun May 01 00:00:00 2022
2070+
Wed Jun 01 00:00:00 2022
2071+
Fri Jul 01 00:00:00 2022
2072+
Mon Aug 01 00:00:00 2022
2073+
Thu Sep 01 00:00:00 2022
2074+
Sat Oct 01 00:00:00 2022
2075+
(10 rows)
2076+
20582077
-- errors
2059-
select * from generate_series('-infinity'::timestamp,
2060-
'2020-01-02 03:00'::timestamp,
2061-
'1 hour'::interval);
2062-
ERROR: start value cannot be infinity
2063-
select * from generate_series('2020-01-01 00:00'::timestamp,
2064-
'infinity'::timestamp,
2065-
'1 hour'::interval);
2066-
ERROR: stop value cannot be infinity
20672078
select * from generate_series('2020-01-01 00:00'::timestamp,
20682079
'2020-01-02 03:00'::timestamp,
20692080
'0 hour'::interval);

src/test/regress/expected/timestamptz.out

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2398,15 +2398,26 @@ select * from generate_series('2020-01-01 00:00'::timestamptz,
23982398
Thu Jan 02 03:00:00 2020 PST
23992399
(28 rows)
24002400

2401+
-- the LIMIT should allow this to terminate in a reasonable amount of time
2402+
-- (but that unfortunately doesn't work yet for SELECT * FROM ...)
2403+
select generate_series('2022-01-01 00:00'::timestamptz,
2404+
'infinity'::timestamptz,
2405+
'1 month'::interval) limit 10;
2406+
generate_series
2407+
------------------------------
2408+
Sat Jan 01 00:00:00 2022 PST
2409+
Tue Feb 01 00:00:00 2022 PST
2410+
Tue Mar 01 00:00:00 2022 PST
2411+
Fri Apr 01 00:00:00 2022 PDT
2412+
Sun May 01 00:00:00 2022 PDT
2413+
Wed Jun 01 00:00:00 2022 PDT
2414+
Fri Jul 01 00:00:00 2022 PDT
2415+
Mon Aug 01 00:00:00 2022 PDT
2416+
Thu Sep 01 00:00:00 2022 PDT
2417+
Sat Oct 01 00:00:00 2022 PDT
2418+
(10 rows)
2419+
24012420
-- errors
2402-
select * from generate_series('-infinity'::timestamptz,
2403-
'2020-01-02 03:00'::timestamptz,
2404-
'1 hour'::interval);
2405-
ERROR: start value cannot be infinity
2406-
select * from generate_series('2020-01-01 00:00'::timestamptz,
2407-
'infinity'::timestamptz,
2408-
'1 hour'::interval);
2409-
ERROR: stop value cannot be infinity
24102421
select * from generate_series('2020-01-01 00:00'::timestamptz,
24112422
'2020-01-02 03:00'::timestamptz,
24122423
'0 hour'::interval);

src/test/regress/sql/timestamp.sql

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -375,13 +375,12 @@ select make_timestamp(0, 7, 15, 12, 30, 15);
375375
select * from generate_series('2020-01-01 00:00'::timestamp,
376376
'2020-01-02 03:00'::timestamp,
377377
'1 hour'::interval);
378+
-- the LIMIT should allow this to terminate in a reasonable amount of time
379+
-- (but that unfortunately doesn't work yet for SELECT * FROM ...)
380+
select generate_series('2022-01-01 00:00'::timestamp,
381+
'infinity'::timestamp,
382+
'1 month'::interval) limit 10;
378383
-- errors
379-
select * from generate_series('-infinity'::timestamp,
380-
'2020-01-02 03:00'::timestamp,
381-
'1 hour'::interval);
382-
select * from generate_series('2020-01-01 00:00'::timestamp,
383-
'infinity'::timestamp,
384-
'1 hour'::interval);
385384
select * from generate_series('2020-01-01 00:00'::timestamp,
386385
'2020-01-02 03:00'::timestamp,
387386
'0 hour'::interval);

src/test/regress/sql/timestamptz.sql

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -436,13 +436,12 @@ RESET TimeZone;
436436
select * from generate_series('2020-01-01 00:00'::timestamptz,
437437
'2020-01-02 03:00'::timestamptz,
438438
'1 hour'::interval);
439+
-- the LIMIT should allow this to terminate in a reasonable amount of time
440+
-- (but that unfortunately doesn't work yet for SELECT * FROM ...)
441+
select generate_series('2022-01-01 00:00'::timestamptz,
442+
'infinity'::timestamptz,
443+
'1 month'::interval) limit 10;
439444
-- errors
440-
select * from generate_series('-infinity'::timestamptz,
441-
'2020-01-02 03:00'::timestamptz,
442-
'1 hour'::interval);
443-
select * from generate_series('2020-01-01 00:00'::timestamptz,
444-
'infinity'::timestamptz,
445-
'1 hour'::interval);
446445
select * from generate_series('2020-01-01 00:00'::timestamptz,
447446
'2020-01-02 03:00'::timestamptz,
448447
'0 hour'::interval);

0 commit comments

Comments
 (0)