diff --git a/src/backend/utils/adt/timestamp.c b/src/backend/utils/adt/timestamp.c index a114ff3a04..fbe3c29ee1 100644 --- a/src/backend/utils/adt/timestamp.c +++ b/src/backend/utils/adt/timestamp.c @@ -5757,20 +5757,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(); @@ -5851,20 +5837,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(); diff --git a/src/test/regress/expected/timestamp.out b/src/test/regress/expected/timestamp.out index d5ca6b76a4..79f8180955 100644 --- a/src/test/regress/expected/timestamp.out +++ b/src/test/regress/expected/timestamp.out @@ -2055,15 +2055,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); diff --git a/src/test/regress/expected/timestamptz.out b/src/test/regress/expected/timestamptz.out index f0624b71f2..a0df947e27 100644 --- a/src/test/regress/expected/timestamptz.out +++ b/src/test/regress/expected/timestamptz.out @@ -2333,15 +2333,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); diff --git a/src/test/regress/sql/timestamp.sql b/src/test/regress/sql/timestamp.sql index 0778e5d7c0..ebc969f36c 100644 --- a/src/test/regress/sql/timestamp.sql +++ b/src/test/regress/sql/timestamp.sql @@ -375,13 +375,12 @@ select make_timestamp(0, 7, 15, 12, 30, 15); 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); diff --git a/src/test/regress/sql/timestamptz.sql b/src/test/regress/sql/timestamptz.sql index b355fb8fe3..bce70fb21f 100644 --- a/src/test/regress/sql/timestamptz.sql +++ b/src/test/regress/sql/timestamptz.sql @@ -414,13 +414,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);