Skip to content

Commit c0406fa

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 34ff156 commit c0406fa

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
@@ -5305,20 +5305,6 @@ generate_series_timestamp(PG_FUNCTION_ARGS)
53055305
MemoryContext oldcontext;
53065306
Interval interval_zero;
53075307

5308-
/* Reject infinities in start and stop values */
5309-
if (TIMESTAMP_IS_NOBEGIN(start) ||
5310-
TIMESTAMP_IS_NOEND(start))
5311-
ereport(ERROR,
5312-
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
5313-
errmsg("start value cannot be infinity")));
5314-
if (TIMESTAMP_IS_NOBEGIN(finish) ||
5315-
TIMESTAMP_IS_NOEND(finish))
5316-
ereport(ERROR,
5317-
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
5318-
errmsg("stop value cannot be infinity")));
5319-
5320-
/* Interval doesn't (currently) have infinity, so nothing to check */
5321-
53225308
/* create a function context for cross-call persistence */
53235309
funcctx = SRF_FIRSTCALL_INIT();
53245310

@@ -5400,20 +5386,6 @@ generate_series_timestamptz(PG_FUNCTION_ARGS)
54005386
MemoryContext oldcontext;
54015387
Interval interval_zero;
54025388

5403-
/* Reject infinities in start and stop values */
5404-
if (TIMESTAMP_IS_NOBEGIN(start) ||
5405-
TIMESTAMP_IS_NOEND(start))
5406-
ereport(ERROR,
5407-
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
5408-
errmsg("start value cannot be infinity")));
5409-
if (TIMESTAMP_IS_NOBEGIN(finish) ||
5410-
TIMESTAMP_IS_NOEND(finish))
5411-
ereport(ERROR,
5412-
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
5413-
errmsg("stop value cannot be infinity")));
5414-
5415-
/* Interval doesn't (currently) have infinity, so nothing to check */
5416-
54175389
/* create a function context for cross-call persistence */
54185390
funcctx = SRF_FIRSTCALL_INIT();
54195391

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

2125+
-- the LIMIT should allow this to terminate in a reasonable amount of time
2126+
-- (but that unfortunately doesn't work yet for SELECT * FROM ...)
2127+
select generate_series('2022-01-01 00:00'::timestamptz,
2128+
'infinity'::timestamptz,
2129+
'1 month'::interval) limit 10;
2130+
generate_series
2131+
------------------------------
2132+
Sat Jan 01 00:00:00 2022 PST
2133+
Tue Feb 01 00:00:00 2022 PST
2134+
Tue Mar 01 00:00:00 2022 PST
2135+
Fri Apr 01 00:00:00 2022 PDT
2136+
Sun May 01 00:00:00 2022 PDT
2137+
Wed Jun 01 00:00:00 2022 PDT
2138+
Fri Jul 01 00:00:00 2022 PDT
2139+
Mon Aug 01 00:00:00 2022 PDT
2140+
Thu Sep 01 00:00:00 2022 PDT
2141+
Sat Oct 01 00:00:00 2022 PDT
2142+
(10 rows)
2143+
21252144
-- errors
2126-
select * from generate_series('-infinity'::timestamptz,
2127-
'2020-01-02 03:00'::timestamptz,
2128-
'1 hour'::interval);
2129-
ERROR: start value cannot be infinity
2130-
select * from generate_series('2020-01-01 00:00'::timestamptz,
2131-
'infinity'::timestamptz,
2132-
'1 hour'::interval);
2133-
ERROR: stop value cannot be infinity
21342145
select * from generate_series('2020-01-01 00:00'::timestamptz,
21352146
'2020-01-02 03:00'::timestamptz,
21362147
'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
@@ -338,13 +338,12 @@ RESET TimeZone;
338338
select * from generate_series('2020-01-01 00:00'::timestamptz,
339339
'2020-01-02 03:00'::timestamptz,
340340
'1 hour'::interval);
341+
-- the LIMIT should allow this to terminate in a reasonable amount of time
342+
-- (but that unfortunately doesn't work yet for SELECT * FROM ...)
343+
select generate_series('2022-01-01 00:00'::timestamptz,
344+
'infinity'::timestamptz,
345+
'1 month'::interval) limit 10;
341346
-- errors
342-
select * from generate_series('-infinity'::timestamptz,
343-
'2020-01-02 03:00'::timestamptz,
344-
'1 hour'::interval);
345-
select * from generate_series('2020-01-01 00:00'::timestamptz,
346-
'infinity'::timestamptz,
347-
'1 hour'::interval);
348347
select * from generate_series('2020-01-01 00:00'::timestamptz,
349348
'2020-01-02 03:00'::timestamptz,
350349
'0 hour'::interval);

0 commit comments

Comments
 (0)