Skip to content

Commit 86a2180

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 f26d570 commit 86a2180

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
@@ -5165,20 +5165,6 @@ generate_series_timestamp(PG_FUNCTION_ARGS)
51655165
MemoryContext oldcontext;
51665166
Interval interval_zero;
51675167

5168-
/* Reject infinities in start and stop values */
5169-
if (TIMESTAMP_IS_NOBEGIN(start) ||
5170-
TIMESTAMP_IS_NOEND(start))
5171-
ereport(ERROR,
5172-
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
5173-
errmsg("start value cannot be infinity")));
5174-
if (TIMESTAMP_IS_NOBEGIN(finish) ||
5175-
TIMESTAMP_IS_NOEND(finish))
5176-
ereport(ERROR,
5177-
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
5178-
errmsg("stop value cannot be infinity")));
5179-
5180-
/* Interval doesn't (currently) have infinity, so nothing to check */
5181-
51825168
/* create a function context for cross-call persistence */
51835169
funcctx = SRF_FIRSTCALL_INIT();
51845170

@@ -5260,20 +5246,6 @@ generate_series_timestamptz(PG_FUNCTION_ARGS)
52605246
MemoryContext oldcontext;
52615247
Interval interval_zero;
52625248

5263-
/* Reject infinities in start and stop values */
5264-
if (TIMESTAMP_IS_NOBEGIN(start) ||
5265-
TIMESTAMP_IS_NOEND(start))
5266-
ereport(ERROR,
5267-
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
5268-
errmsg("start value cannot be infinity")));
5269-
if (TIMESTAMP_IS_NOBEGIN(finish) ||
5270-
TIMESTAMP_IS_NOEND(finish))
5271-
ereport(ERROR,
5272-
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
5273-
errmsg("stop value cannot be infinity")));
5274-
5275-
/* Interval doesn't (currently) have infinity, so nothing to check */
5276-
52775249
/* create a function context for cross-call persistence */
52785250
funcctx = SRF_FIRSTCALL_INIT();
52795251

src/test/regress/expected/timestamp.out

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

1783+
-- the LIMIT should allow this to terminate in a reasonable amount of time
1784+
-- (but that unfortunately doesn't work yet for SELECT * FROM ...)
1785+
select generate_series('2022-01-01 00:00'::timestamp,
1786+
'infinity'::timestamp,
1787+
'1 month'::interval) limit 10;
1788+
generate_series
1789+
--------------------------
1790+
Sat Jan 01 00:00:00 2022
1791+
Tue Feb 01 00:00:00 2022
1792+
Tue Mar 01 00:00:00 2022
1793+
Fri Apr 01 00:00:00 2022
1794+
Sun May 01 00:00:00 2022
1795+
Wed Jun 01 00:00:00 2022
1796+
Fri Jul 01 00:00:00 2022
1797+
Mon Aug 01 00:00:00 2022
1798+
Thu Sep 01 00:00:00 2022
1799+
Sat Oct 01 00:00:00 2022
1800+
(10 rows)
1801+
17831802
-- errors
1784-
select * from generate_series('-infinity'::timestamp,
1785-
'2020-01-02 03:00'::timestamp,
1786-
'1 hour'::interval);
1787-
ERROR: start value cannot be infinity
1788-
select * from generate_series('2020-01-01 00:00'::timestamp,
1789-
'infinity'::timestamp,
1790-
'1 hour'::interval);
1791-
ERROR: stop value cannot be infinity
17921803
select * from generate_series('2020-01-01 00:00'::timestamp,
17931804
'2020-01-02 03:00'::timestamp,
17941805
'0 hour'::interval);

src/test/regress/expected/timestamptz.out

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

2111+
-- the LIMIT should allow this to terminate in a reasonable amount of time
2112+
-- (but that unfortunately doesn't work yet for SELECT * FROM ...)
2113+
select generate_series('2022-01-01 00:00'::timestamptz,
2114+
'infinity'::timestamptz,
2115+
'1 month'::interval) limit 10;
2116+
generate_series
2117+
------------------------------
2118+
Sat Jan 01 00:00:00 2022 PST
2119+
Tue Feb 01 00:00:00 2022 PST
2120+
Tue Mar 01 00:00:00 2022 PST
2121+
Fri Apr 01 00:00:00 2022 PDT
2122+
Sun May 01 00:00:00 2022 PDT
2123+
Wed Jun 01 00:00:00 2022 PDT
2124+
Fri Jul 01 00:00:00 2022 PDT
2125+
Mon Aug 01 00:00:00 2022 PDT
2126+
Thu Sep 01 00:00:00 2022 PDT
2127+
Sat Oct 01 00:00:00 2022 PDT
2128+
(10 rows)
2129+
21112130
-- errors
2112-
select * from generate_series('-infinity'::timestamptz,
2113-
'2020-01-02 03:00'::timestamptz,
2114-
'1 hour'::interval);
2115-
ERROR: start value cannot be infinity
2116-
select * from generate_series('2020-01-01 00:00'::timestamptz,
2117-
'infinity'::timestamptz,
2118-
'1 hour'::interval);
2119-
ERROR: stop value cannot be infinity
21202131
select * from generate_series('2020-01-01 00:00'::timestamptz,
21212132
'2020-01-02 03:00'::timestamptz,
21222133
'0 hour'::interval);

src/test/regress/sql/timestamp.sql

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -248,13 +248,12 @@ SELECT make_timestamp(2014,12,28,6,30,45.887);
248248
select * from generate_series('2020-01-01 00:00'::timestamp,
249249
'2020-01-02 03:00'::timestamp,
250250
'1 hour'::interval);
251+
-- the LIMIT should allow this to terminate in a reasonable amount of time
252+
-- (but that unfortunately doesn't work yet for SELECT * FROM ...)
253+
select generate_series('2022-01-01 00:00'::timestamp,
254+
'infinity'::timestamp,
255+
'1 month'::interval) limit 10;
251256
-- errors
252-
select * from generate_series('-infinity'::timestamp,
253-
'2020-01-02 03:00'::timestamp,
254-
'1 hour'::interval);
255-
select * from generate_series('2020-01-01 00:00'::timestamp,
256-
'infinity'::timestamp,
257-
'1 hour'::interval);
258257
select * from generate_series('2020-01-01 00:00'::timestamp,
259258
'2020-01-02 03:00'::timestamp,
260259
'0 hour'::interval);

src/test/regress/sql/timestamptz.sql

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -334,13 +334,12 @@ RESET TimeZone;
334334
select * from generate_series('2020-01-01 00:00'::timestamptz,
335335
'2020-01-02 03:00'::timestamptz,
336336
'1 hour'::interval);
337+
-- the LIMIT should allow this to terminate in a reasonable amount of time
338+
-- (but that unfortunately doesn't work yet for SELECT * FROM ...)
339+
select generate_series('2022-01-01 00:00'::timestamptz,
340+
'infinity'::timestamptz,
341+
'1 month'::interval) limit 10;
337342
-- errors
338-
select * from generate_series('-infinity'::timestamptz,
339-
'2020-01-02 03:00'::timestamptz,
340-
'1 hour'::interval);
341-
select * from generate_series('2020-01-01 00:00'::timestamptz,
342-
'infinity'::timestamptz,
343-
'1 hour'::interval);
344343
select * from generate_series('2020-01-01 00:00'::timestamptz,
345344
'2020-01-02 03:00'::timestamptz,
346345
'0 hour'::interval);

0 commit comments

Comments
 (0)