]> git.ipfire.org Git - thirdparty/postgresql.git/commitdiff
Revert "Disallow infinite endpoints in generate_series() for timestamps."
authorTom Lane <tgl@sss.pgh.pa.us>
Mon, 9 May 2022 15:02:37 +0000 (11:02 -0400)
committerTom Lane <tgl@sss.pgh.pa.us>
Mon, 9 May 2022 15:40:41 +0000 (11:40 -0400)
This reverts commit eafdf9de06e9b60168f5e47cedcfceecdc6d4b5f
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

src/backend/utils/adt/timestamp.c
src/test/regress/expected/timestamp.out
src/test/regress/expected/timestamptz.out
src/test/regress/sql/timestamp.sql
src/test/regress/sql/timestamptz.sql

index a6161198f8ef5d2983e6f7c2ccc80f883ef7f0ae..3e7c77ee48fab3d5d07ecc9d379ab7aecf786515 100644 (file)
@@ -5392,20 +5392,6 @@ generate_series_timestamp(PG_FUNCTION_ARGS)
                MemoryContext oldcontext;
                Interval        interval_zero;
 
-               /* Reject infinities in start and stop values */
-               if (TIMESTAMP_IS_NOBEGIN(start) ||
-                       TIMESTAMP_IS_NOEND(start))
-                       ereport(ERROR,
-                                       (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
-                                        errmsg("start value cannot be infinity")));
-               if (TIMESTAMP_IS_NOBEGIN(finish) ||
-                       TIMESTAMP_IS_NOEND(finish))
-                       ereport(ERROR,
-                                       (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
-                                        errmsg("stop value cannot be infinity")));
-
-               /* Interval doesn't (currently) have infinity, so nothing to check */
-
                /* create a function context for cross-call persistence */
                funcctx = SRF_FIRSTCALL_INIT();
 
@@ -5487,20 +5473,6 @@ generate_series_timestamptz(PG_FUNCTION_ARGS)
                MemoryContext oldcontext;
                Interval        interval_zero;
 
-               /* Reject infinities in start and stop values */
-               if (TIMESTAMP_IS_NOBEGIN(start) ||
-                       TIMESTAMP_IS_NOEND(start))
-                       ereport(ERROR,
-                                       (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
-                                        errmsg("start value cannot be infinity")));
-               if (TIMESTAMP_IS_NOBEGIN(finish) ||
-                       TIMESTAMP_IS_NOEND(finish))
-                       ereport(ERROR,
-                                       (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
-                                        errmsg("stop value cannot be infinity")));
-
-               /* Interval doesn't (currently) have infinity, so nothing to check */
-
                /* create a function context for cross-call persistence */
                funcctx = SRF_FIRSTCALL_INIT();
 
index d6f7a91ffd8a8b940877b7daef7ba3ca5bedaf09..fe9050f0dbedf63a880cf55225b4c26bfaac5587 100644 (file)
@@ -1767,15 +1767,26 @@ select * from generate_series('2020-01-01 00:00'::timestamp,
  Thu Jan 02 03:00:00 2020
 (28 rows)
 
+-- the LIMIT should allow this to terminate in a reasonable amount of time
+-- (but that unfortunately doesn't work yet for SELECT * FROM ...)
+select generate_series('2022-01-01 00:00'::timestamp,
+                       'infinity'::timestamp,
+                       '1 month'::interval) limit 10;
+     generate_series      
+--------------------------
+ Sat Jan 01 00:00:00 2022
+ Tue Feb 01 00:00:00 2022
+ Tue Mar 01 00:00:00 2022
+ Fri Apr 01 00:00:00 2022
+ Sun May 01 00:00:00 2022
+ Wed Jun 01 00:00:00 2022
+ Fri Jul 01 00:00:00 2022
+ Mon Aug 01 00:00:00 2022
+ Thu Sep 01 00:00:00 2022
+ Sat Oct 01 00:00:00 2022
+(10 rows)
+
 -- errors
-select * from generate_series('-infinity'::timestamp,
-                              '2020-01-02 03:00'::timestamp,
-                              '1 hour'::interval);
-ERROR:  start value cannot be infinity
-select * from generate_series('2020-01-01 00:00'::timestamp,
-                              'infinity'::timestamp,
-                              '1 hour'::interval);
-ERROR:  stop value cannot be infinity
 select * from generate_series('2020-01-01 00:00'::timestamp,
                               '2020-01-02 03:00'::timestamp,
                               '0 hour'::interval);
index 8a905aba8d41b50fcc8b821ccf9ebbec5fdaeca6..bc7879f288d1cf9831ac87a8b28f638c0235ce5e 100644 (file)
@@ -2127,15 +2127,26 @@ select * from generate_series('2020-01-01 00:00'::timestamptz,
  Thu Jan 02 03:00:00 2020 PST
 (28 rows)
 
+-- the LIMIT should allow this to terminate in a reasonable amount of time
+-- (but that unfortunately doesn't work yet for SELECT * FROM ...)
+select generate_series('2022-01-01 00:00'::timestamptz,
+                       'infinity'::timestamptz,
+                       '1 month'::interval) limit 10;
+       generate_series        
+------------------------------
+ Sat Jan 01 00:00:00 2022 PST
+ Tue Feb 01 00:00:00 2022 PST
+ Tue Mar 01 00:00:00 2022 PST
+ Fri Apr 01 00:00:00 2022 PDT
+ Sun May 01 00:00:00 2022 PDT
+ Wed Jun 01 00:00:00 2022 PDT
+ Fri Jul 01 00:00:00 2022 PDT
+ Mon Aug 01 00:00:00 2022 PDT
+ Thu Sep 01 00:00:00 2022 PDT
+ Sat Oct 01 00:00:00 2022 PDT
+(10 rows)
+
 -- errors
-select * from generate_series('-infinity'::timestamptz,
-                              '2020-01-02 03:00'::timestamptz,
-                              '1 hour'::interval);
-ERROR:  start value cannot be infinity
-select * from generate_series('2020-01-01 00:00'::timestamptz,
-                              'infinity'::timestamptz,
-                              '1 hour'::interval);
-ERROR:  stop value cannot be infinity
 select * from generate_series('2020-01-01 00:00'::timestamptz,
                               '2020-01-02 03:00'::timestamptz,
                               '0 hour'::interval);
index 947dbfc3259005cbd17cb0627d120a5a467cca5d..0677ef947cd5206267002d0643ff95b17d4ca1cf 100644 (file)
@@ -244,13 +244,12 @@ SELECT make_timestamp(2014,12,28,6,30,45.887);
 select * from generate_series('2020-01-01 00:00'::timestamp,
                               '2020-01-02 03:00'::timestamp,
                               '1 hour'::interval);
+-- the LIMIT should allow this to terminate in a reasonable amount of time
+-- (but that unfortunately doesn't work yet for SELECT * FROM ...)
+select generate_series('2022-01-01 00:00'::timestamp,
+                       'infinity'::timestamp,
+                       '1 month'::interval) limit 10;
 -- errors
-select * from generate_series('-infinity'::timestamp,
-                              '2020-01-02 03:00'::timestamp,
-                              '1 hour'::interval);
-select * from generate_series('2020-01-01 00:00'::timestamp,
-                              'infinity'::timestamp,
-                              '1 hour'::interval);
 select * from generate_series('2020-01-01 00:00'::timestamp,
                               '2020-01-02 03:00'::timestamp,
                               '0 hour'::interval);
index e67d33fb5fd54d46328f027600b56a99208e1c51..dd22c3296c8541c5cb22e05194010804b36164ff 100644 (file)
@@ -338,13 +338,12 @@ RESET TimeZone;
 select * from generate_series('2020-01-01 00:00'::timestamptz,
                               '2020-01-02 03:00'::timestamptz,
                               '1 hour'::interval);
+-- the LIMIT should allow this to terminate in a reasonable amount of time
+-- (but that unfortunately doesn't work yet for SELECT * FROM ...)
+select generate_series('2022-01-01 00:00'::timestamptz,
+                       'infinity'::timestamptz,
+                       '1 month'::interval) limit 10;
 -- errors
-select * from generate_series('-infinity'::timestamptz,
-                              '2020-01-02 03:00'::timestamptz,
-                              '1 hour'::interval);
-select * from generate_series('2020-01-01 00:00'::timestamptz,
-                              'infinity'::timestamptz,
-                              '1 hour'::interval);
 select * from generate_series('2020-01-01 00:00'::timestamptz,
                               '2020-01-02 03:00'::timestamptz,
                               '0 hour'::interval);