Skip to content

Commit 9b5797c

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 677a494 commit 9b5797c

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
@@ -5757,20 +5757,6 @@ generate_series_timestamp(PG_FUNCTION_ARGS)
57575757
MemoryContext oldcontext;
57585758
Interval interval_zero;
57595759

5760-
/* Reject infinities in start and stop values */
5761-
if (TIMESTAMP_IS_NOBEGIN(start) ||
5762-
TIMESTAMP_IS_NOEND(start))
5763-
ereport(ERROR,
5764-
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
5765-
errmsg("start value cannot be infinity")));
5766-
if (TIMESTAMP_IS_NOBEGIN(finish) ||
5767-
TIMESTAMP_IS_NOEND(finish))
5768-
ereport(ERROR,
5769-
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
5770-
errmsg("stop value cannot be infinity")));
5771-
5772-
/* Interval doesn't (currently) have infinity, so nothing to check */
5773-
57745760
/* create a function context for cross-call persistence */
57755761
funcctx = SRF_FIRSTCALL_INIT();
57765762

@@ -5851,20 +5837,6 @@ generate_series_timestamptz(PG_FUNCTION_ARGS)
58515837
MemoryContext oldcontext;
58525838
Interval interval_zero;
58535839

5854-
/* Reject infinities in start and stop values */
5855-
if (TIMESTAMP_IS_NOBEGIN(start) ||
5856-
TIMESTAMP_IS_NOEND(start))
5857-
ereport(ERROR,
5858-
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
5859-
errmsg("start value cannot be infinity")));
5860-
if (TIMESTAMP_IS_NOBEGIN(finish) ||
5861-
TIMESTAMP_IS_NOEND(finish))
5862-
ereport(ERROR,
5863-
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
5864-
errmsg("stop value cannot be infinity")));
5865-
5866-
/* Interval doesn't (currently) have infinity, so nothing to check */
5867-
58685840
/* create a function context for cross-call persistence */
58695841
funcctx = SRF_FIRSTCALL_INIT();
58705842

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
@@ -2333,15 +2333,26 @@ select * from generate_series('2020-01-01 00:00'::timestamptz,
23332333
Thu Jan 02 03:00:00 2020 PST
23342334
(28 rows)
23352335

2336+
-- the LIMIT should allow this to terminate in a reasonable amount of time
2337+
-- (but that unfortunately doesn't work yet for SELECT * FROM ...)
2338+
select generate_series('2022-01-01 00:00'::timestamptz,
2339+
'infinity'::timestamptz,
2340+
'1 month'::interval) limit 10;
2341+
generate_series
2342+
------------------------------
2343+
Sat Jan 01 00:00:00 2022 PST
2344+
Tue Feb 01 00:00:00 2022 PST
2345+
Tue Mar 01 00:00:00 2022 PST
2346+
Fri Apr 01 00:00:00 2022 PDT
2347+
Sun May 01 00:00:00 2022 PDT
2348+
Wed Jun 01 00:00:00 2022 PDT
2349+
Fri Jul 01 00:00:00 2022 PDT
2350+
Mon Aug 01 00:00:00 2022 PDT
2351+
Thu Sep 01 00:00:00 2022 PDT
2352+
Sat Oct 01 00:00:00 2022 PDT
2353+
(10 rows)
2354+
23362355
-- errors
2337-
select * from generate_series('-infinity'::timestamptz,
2338-
'2020-01-02 03:00'::timestamptz,
2339-
'1 hour'::interval);
2340-
ERROR: start value cannot be infinity
2341-
select * from generate_series('2020-01-01 00:00'::timestamptz,
2342-
'infinity'::timestamptz,
2343-
'1 hour'::interval);
2344-
ERROR: stop value cannot be infinity
23452356
select * from generate_series('2020-01-01 00:00'::timestamptz,
23462357
'2020-01-02 03:00'::timestamptz,
23472358
'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
@@ -414,13 +414,12 @@ RESET TimeZone;
414414
select * from generate_series('2020-01-01 00:00'::timestamptz,
415415
'2020-01-02 03:00'::timestamptz,
416416
'1 hour'::interval);
417+
-- the LIMIT should allow this to terminate in a reasonable amount of time
418+
-- (but that unfortunately doesn't work yet for SELECT * FROM ...)
419+
select generate_series('2022-01-01 00:00'::timestamptz,
420+
'infinity'::timestamptz,
421+
'1 month'::interval) limit 10;
417422
-- errors
418-
select * from generate_series('-infinity'::timestamptz,
419-
'2020-01-02 03:00'::timestamptz,
420-
'1 hour'::interval);
421-
select * from generate_series('2020-01-01 00:00'::timestamptz,
422-
'infinity'::timestamptz,
423-
'1 hour'::interval);
424423
select * from generate_series('2020-01-01 00:00'::timestamptz,
425424
'2020-01-02 03:00'::timestamptz,
426425
'0 hour'::interval);

0 commit comments

Comments
 (0)