Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 7f0754b

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 88743d5 commit 7f0754b

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
@@ -5426,20 +5426,6 @@ generate_series_timestamp(PG_FUNCTION_ARGS)
54265426
MemoryContext oldcontext;
54275427
Interval interval_zero;
54285428

5429-
/* Reject infinities in start and stop values */
5430-
if (TIMESTAMP_IS_NOBEGIN(start) ||
5431-
TIMESTAMP_IS_NOEND(start))
5432-
ereport(ERROR,
5433-
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
5434-
errmsg("start value cannot be infinity")));
5435-
if (TIMESTAMP_IS_NOBEGIN(finish) ||
5436-
TIMESTAMP_IS_NOEND(finish))
5437-
ereport(ERROR,
5438-
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
5439-
errmsg("stop value cannot be infinity")));
5440-
5441-
/* Interval doesn't (currently) have infinity, so nothing to check */
5442-
54435429
/* create a function context for cross-call persistence */
54445430
funcctx = SRF_FIRSTCALL_INIT();
54455431

@@ -5520,20 +5506,6 @@ generate_series_timestamptz(PG_FUNCTION_ARGS)
55205506
MemoryContext oldcontext;
55215507
Interval interval_zero;
55225508

5523-
/* Reject infinities in start and stop values */
5524-
if (TIMESTAMP_IS_NOBEGIN(start) ||
5525-
TIMESTAMP_IS_NOEND(start))
5526-
ereport(ERROR,
5527-
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
5528-
errmsg("start value cannot be infinity")));
5529-
if (TIMESTAMP_IS_NOBEGIN(finish) ||
5530-
TIMESTAMP_IS_NOEND(finish))
5531-
ereport(ERROR,
5532-
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
5533-
errmsg("stop value cannot be infinity")));
5534-
5535-
/* Interval doesn't (currently) have infinity, so nothing to check */
5536-
55375509
/* create a function context for cross-call persistence */
55385510
funcctx = SRF_FIRSTCALL_INIT();
55395511

src/test/regress/expected/timestamp.out

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

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

src/test/regress/expected/timestamptz.out

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

2145+
-- the LIMIT should allow this to terminate in a reasonable amount of time
2146+
-- (but that unfortunately doesn't work yet for SELECT * FROM ...)
2147+
select generate_series('2022-01-01 00:00'::timestamptz,
2148+
'infinity'::timestamptz,
2149+
'1 month'::interval) limit 10;
2150+
generate_series
2151+
------------------------------
2152+
Sat Jan 01 00:00:00 2022 PST
2153+
Tue Feb 01 00:00:00 2022 PST
2154+
Tue Mar 01 00:00:00 2022 PST
2155+
Fri Apr 01 00:00:00 2022 PDT
2156+
Sun May 01 00:00:00 2022 PDT
2157+
Wed Jun 01 00:00:00 2022 PDT
2158+
Fri Jul 01 00:00:00 2022 PDT
2159+
Mon Aug 01 00:00:00 2022 PDT
2160+
Thu Sep 01 00:00:00 2022 PDT
2161+
Sat Oct 01 00:00:00 2022 PDT
2162+
(10 rows)
2163+
21452164
-- errors
2146-
select * from generate_series('-infinity'::timestamptz,
2147-
'2020-01-02 03:00'::timestamptz,
2148-
'1 hour'::interval);
2149-
ERROR: start value cannot be infinity
2150-
select * from generate_series('2020-01-01 00:00'::timestamptz,
2151-
'infinity'::timestamptz,
2152-
'1 hour'::interval);
2153-
ERROR: stop value cannot be infinity
21542165
select * from generate_series('2020-01-01 00:00'::timestamptz,
21552166
'2020-01-02 03:00'::timestamptz,
21562167
'0 hour'::interval);

src/test/regress/sql/timestamp.sql

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -252,13 +252,12 @@ SELECT make_timestamp(2014,12,28,6,30,45.887);
252252
select * from generate_series('2020-01-01 00:00'::timestamp,
253253
'2020-01-02 03:00'::timestamp,
254254
'1 hour'::interval);
255+
-- the LIMIT should allow this to terminate in a reasonable amount of time
256+
-- (but that unfortunately doesn't work yet for SELECT * FROM ...)
257+
select generate_series('2022-01-01 00:00'::timestamp,
258+
'infinity'::timestamp,
259+
'1 month'::interval) limit 10;
255260
-- errors
256-
select * from generate_series('-infinity'::timestamp,
257-
'2020-01-02 03:00'::timestamp,
258-
'1 hour'::interval);
259-
select * from generate_series('2020-01-01 00:00'::timestamp,
260-
'infinity'::timestamp,
261-
'1 hour'::interval);
262261
select * from generate_series('2020-01-01 00:00'::timestamp,
263262
'2020-01-02 03:00'::timestamp,
264263
'0 hour'::interval);

src/test/regress/sql/timestamptz.sql

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -346,13 +346,12 @@ RESET TimeZone;
346346
select * from generate_series('2020-01-01 00:00'::timestamptz,
347347
'2020-01-02 03:00'::timestamptz,
348348
'1 hour'::interval);
349+
-- the LIMIT should allow this to terminate in a reasonable amount of time
350+
-- (but that unfortunately doesn't work yet for SELECT * FROM ...)
351+
select generate_series('2022-01-01 00:00'::timestamptz,
352+
'infinity'::timestamptz,
353+
'1 month'::interval) limit 10;
349354
-- errors
350-
select * from generate_series('-infinity'::timestamptz,
351-
'2020-01-02 03:00'::timestamptz,
352-
'1 hour'::interval);
353-
select * from generate_series('2020-01-01 00:00'::timestamptz,
354-
'infinity'::timestamptz,
355-
'1 hour'::interval);
356355
select * from generate_series('2020-01-01 00:00'::timestamptz,
357356
'2020-01-02 03:00'::timestamptz,
358357
'0 hour'::interval);

0 commit comments

Comments
 (0)