Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commite346329

Browse files
committed
Disallow infinite endpoints in generate_series() for timestamps.
Such cases will lead to infinite loops, so they're of no practicalvalue. The numeric variant of generate_series() already threw errorfor this, so borrow its message wording.Per report from Richard Wesley. Back-patch to all supported branches.Discussion:https://postgr.es/m/91B44E7B-68D5-448F-95C8-B4B3B0F5DEAF@duckdblabs.com
1 parent4a66300 commite346329

File tree

5 files changed

+156
-0
lines changed

5 files changed

+156
-0
lines changed

‎src/backend/utils/adt/timestamp.c

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5757,6 +5757,20 @@ generate_series_timestamp(PG_FUNCTION_ARGS)
57575757
MemoryContextoldcontext;
57585758
Intervalinterval_zero;
57595759

5760+
/* Reject infinities in start and stop values */
5761+
if (TIMESTAMP_IS_NOBEGIN(start)||
5762+
TIMESTAMP_IS_NOEND(start))
5763+
ereport(ERROR,
5764+
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
5765+
errmsg("start value cannot be infinity")));
5766+
if (TIMESTAMP_IS_NOBEGIN(finish)||
5767+
TIMESTAMP_IS_NOEND(finish))
5768+
ereport(ERROR,
5769+
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
5770+
errmsg("stop value cannot be infinity")));
5771+
5772+
/* Interval doesn't (currently) have infinity, so nothing to check */
5773+
57605774
/* create a function context for cross-call persistence */
57615775
funcctx=SRF_FIRSTCALL_INIT();
57625776

@@ -5837,6 +5851,20 @@ generate_series_timestamptz(PG_FUNCTION_ARGS)
58375851
MemoryContextoldcontext;
58385852
Intervalinterval_zero;
58395853

5854+
/* Reject infinities in start and stop values */
5855+
if (TIMESTAMP_IS_NOBEGIN(start)||
5856+
TIMESTAMP_IS_NOEND(start))
5857+
ereport(ERROR,
5858+
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
5859+
errmsg("start value cannot be infinity")));
5860+
if (TIMESTAMP_IS_NOBEGIN(finish)||
5861+
TIMESTAMP_IS_NOEND(finish))
5862+
ereport(ERROR,
5863+
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
5864+
errmsg("stop value cannot be infinity")));
5865+
5866+
/* Interval doesn't (currently) have infinity, so nothing to check */
5867+
58405868
/* create a function context for cross-call persistence */
58415869
funcctx=SRF_FIRSTCALL_INIT();
58425870

‎src/test/regress/expected/timestamp.out

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2019,3 +2019,52 @@ SELECT make_timestamp(-44, 3, 15, 12, 30, 15);
20192019
-- should fail
20202020
select make_timestamp(0, 7, 15, 12, 30, 15);
20212021
ERROR: date field value out of range: 0-07-15
2022+
-- generate_series for timestamp
2023+
select * from generate_series('2020-01-01 00:00'::timestamp,
2024+
'2020-01-02 03:00'::timestamp,
2025+
'1 hour'::interval);
2026+
generate_series
2027+
--------------------------
2028+
Wed Jan 01 00:00:00 2020
2029+
Wed Jan 01 01:00:00 2020
2030+
Wed Jan 01 02:00:00 2020
2031+
Wed Jan 01 03:00:00 2020
2032+
Wed Jan 01 04:00:00 2020
2033+
Wed Jan 01 05:00:00 2020
2034+
Wed Jan 01 06:00:00 2020
2035+
Wed Jan 01 07:00:00 2020
2036+
Wed Jan 01 08:00:00 2020
2037+
Wed Jan 01 09:00:00 2020
2038+
Wed Jan 01 10:00:00 2020
2039+
Wed Jan 01 11:00:00 2020
2040+
Wed Jan 01 12:00:00 2020
2041+
Wed Jan 01 13:00:00 2020
2042+
Wed Jan 01 14:00:00 2020
2043+
Wed Jan 01 15:00:00 2020
2044+
Wed Jan 01 16:00:00 2020
2045+
Wed Jan 01 17:00:00 2020
2046+
Wed Jan 01 18:00:00 2020
2047+
Wed Jan 01 19:00:00 2020
2048+
Wed Jan 01 20:00:00 2020
2049+
Wed Jan 01 21:00:00 2020
2050+
Wed Jan 01 22:00:00 2020
2051+
Wed Jan 01 23:00:00 2020
2052+
Thu Jan 02 00:00:00 2020
2053+
Thu Jan 02 01:00:00 2020
2054+
Thu Jan 02 02:00:00 2020
2055+
Thu Jan 02 03:00:00 2020
2056+
(28 rows)
2057+
2058+
-- errors
2059+
select * from generate_series('-infinity'::timestamp,
2060+
'2020-01-02 03:00'::timestamp,
2061+
'1 hour'::interval);
2062+
ERROR: start value cannot be infinity
2063+
select * from generate_series('2020-01-01 00:00'::timestamp,
2064+
'infinity'::timestamp,
2065+
'1 hour'::interval);
2066+
ERROR: stop value cannot be infinity
2067+
select * from generate_series('2020-01-01 00:00'::timestamp,
2068+
'2020-01-02 03:00'::timestamp,
2069+
'0 hour'::interval);
2070+
ERROR: step size cannot equal zero

‎src/test/regress/expected/timestamptz.out

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2297,6 +2297,55 @@ SELECT make_timestamptz(2014, 12, 10, 10, 10, 10, 'PST8PDT');
22972297
(1 row)
22982298

22992299
RESET TimeZone;
2300+
-- generate_series for timestamptz
2301+
select * from generate_series('2020-01-01 00:00'::timestamptz,
2302+
'2020-01-02 03:00'::timestamptz,
2303+
'1 hour'::interval);
2304+
generate_series
2305+
------------------------------
2306+
Wed Jan 01 00:00:00 2020 PST
2307+
Wed Jan 01 01:00:00 2020 PST
2308+
Wed Jan 01 02:00:00 2020 PST
2309+
Wed Jan 01 03:00:00 2020 PST
2310+
Wed Jan 01 04:00:00 2020 PST
2311+
Wed Jan 01 05:00:00 2020 PST
2312+
Wed Jan 01 06:00:00 2020 PST
2313+
Wed Jan 01 07:00:00 2020 PST
2314+
Wed Jan 01 08:00:00 2020 PST
2315+
Wed Jan 01 09:00:00 2020 PST
2316+
Wed Jan 01 10:00:00 2020 PST
2317+
Wed Jan 01 11:00:00 2020 PST
2318+
Wed Jan 01 12:00:00 2020 PST
2319+
Wed Jan 01 13:00:00 2020 PST
2320+
Wed Jan 01 14:00:00 2020 PST
2321+
Wed Jan 01 15:00:00 2020 PST
2322+
Wed Jan 01 16:00:00 2020 PST
2323+
Wed Jan 01 17:00:00 2020 PST
2324+
Wed Jan 01 18:00:00 2020 PST
2325+
Wed Jan 01 19:00:00 2020 PST
2326+
Wed Jan 01 20:00:00 2020 PST
2327+
Wed Jan 01 21:00:00 2020 PST
2328+
Wed Jan 01 22:00:00 2020 PST
2329+
Wed Jan 01 23:00:00 2020 PST
2330+
Thu Jan 02 00:00:00 2020 PST
2331+
Thu Jan 02 01:00:00 2020 PST
2332+
Thu Jan 02 02:00:00 2020 PST
2333+
Thu Jan 02 03:00:00 2020 PST
2334+
(28 rows)
2335+
2336+
-- errors
2337+
select * from generate_series('-infinity'::timestamptz,
2338+
'2020-01-02 03:00'::timestamptz,
2339+
'1 hour'::interval);
2340+
ERROR: start value cannot be infinity
2341+
select * from generate_series('2020-01-01 00:00'::timestamptz,
2342+
'infinity'::timestamptz,
2343+
'1 hour'::interval);
2344+
ERROR: stop value cannot be infinity
2345+
select * from generate_series('2020-01-01 00:00'::timestamptz,
2346+
'2020-01-02 03:00'::timestamptz,
2347+
'0 hour'::interval);
2348+
ERROR: step size cannot equal zero
23002349
--
23012350
-- Test behavior with a dynamic (time-varying) timezone abbreviation.
23022351
-- These tests rely on the knowledge that MSK (Europe/Moscow standard time)

‎src/test/regress/sql/timestamp.sql

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -370,3 +370,18 @@ SELECT make_timestamp(2014, 12, 28, 6, 30, 45.887);
370370
SELECT make_timestamp(-44,3,15,12,30,15);
371371
-- should fail
372372
select make_timestamp(0,7,15,12,30,15);
373+
374+
-- generate_series for timestamp
375+
select*from generate_series('2020-01-01 00:00'::timestamp,
376+
'2020-01-02 03:00'::timestamp,
377+
'1 hour'::interval);
378+
-- errors
379+
select*from generate_series('-infinity'::timestamp,
380+
'2020-01-02 03:00'::timestamp,
381+
'1 hour'::interval);
382+
select*from generate_series('2020-01-01 00:00'::timestamp,
383+
'infinity'::timestamp,
384+
'1 hour'::interval);
385+
select*from generate_series('2020-01-01 00:00'::timestamp,
386+
'2020-01-02 03:00'::timestamp,
387+
'0 hour'::interval);

‎src/test/regress/sql/timestamptz.sql

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -410,6 +410,21 @@ SELECT make_timestamptz(2014, 12, 10, 10, 10, 10, 'PST8PDT');
410410

411411
RESET TimeZone;
412412

413+
-- generate_series for timestamptz
414+
select*from generate_series('2020-01-01 00:00'::timestamptz,
415+
'2020-01-02 03:00'::timestamptz,
416+
'1 hour'::interval);
417+
-- errors
418+
select*from generate_series('-infinity'::timestamptz,
419+
'2020-01-02 03:00'::timestamptz,
420+
'1 hour'::interval);
421+
select*from generate_series('2020-01-01 00:00'::timestamptz,
422+
'infinity'::timestamptz,
423+
'1 hour'::interval);
424+
select*from generate_series('2020-01-01 00:00'::timestamptz,
425+
'2020-01-02 03:00'::timestamptz,
426+
'0 hour'::interval);
427+
413428
--
414429
-- Test behavior with a dynamic (time-varying) timezone abbreviation.
415430
-- These tests rely on the knowledge that MSK (Europe/Moscow standard time)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp