Fix division by zero error in date_bin
Bauyrzhan Sakhariyev, via Github Backpatch to v14
This commit is contained in:
parent
b1c1b7af57
commit
81322fc409
@ -3843,6 +3843,11 @@ timestamp_bin(PG_FUNCTION_ARGS)
|
||||
|
||||
stride_usecs = stride->day * USECS_PER_DAY + stride->time;
|
||||
|
||||
if (stride_usecs == 0)
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
|
||||
errmsg("stride cannot equal zero")));
|
||||
|
||||
tm_diff = timestamp - origin;
|
||||
tm_delta = tm_diff - tm_diff % stride_usecs;
|
||||
|
||||
@ -4021,6 +4026,11 @@ timestamptz_bin(PG_FUNCTION_ARGS)
|
||||
|
||||
stride_usecs = stride->day * USECS_PER_DAY + stride->time;
|
||||
|
||||
if (stride_usecs == 0)
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
|
||||
errmsg("stride cannot equal zero")));
|
||||
|
||||
tm_diff = timestamp - origin;
|
||||
tm_delta = tm_diff - tm_diff % stride_usecs;
|
||||
|
||||
|
@ -704,6 +704,9 @@ SELECT date_bin('5 months'::interval, timestamp '2020-02-01 01:01:01', timestamp
|
||||
ERROR: timestamps cannot be binned into intervals containing months or years
|
||||
SELECT date_bin('5 years'::interval, timestamp '2020-02-01 01:01:01', timestamp '2001-01-01');
|
||||
ERROR: timestamps cannot be binned into intervals containing months or years
|
||||
-- disallow zero intervals
|
||||
SELECT date_bin('0 days'::interval, timestamp '1970-01-01 01:00:00' , timestamp '1970-01-01 00:00:00');
|
||||
ERROR: stride cannot equal zero
|
||||
-- Test casting within a BETWEEN qualifier
|
||||
SELECT d1 - timestamp without time zone '1997-01-02' AS diff
|
||||
FROM TIMESTAMP_TBL
|
||||
|
@ -748,6 +748,9 @@ SELECT date_bin('5 months'::interval, timestamp with time zone '2020-02-01 01:01
|
||||
ERROR: timestamps cannot be binned into intervals containing months or years
|
||||
SELECT date_bin('5 years'::interval, timestamp with time zone '2020-02-01 01:01:01+00', timestamp with time zone '2001-01-01+00');
|
||||
ERROR: timestamps cannot be binned into intervals containing months or years
|
||||
-- disallow zero intervals
|
||||
SELECT date_bin('0 days'::interval, timestamp with time zone '1970-01-01 01:00:00+00' , timestamp with time zone '1970-01-01 00:00:00+00');
|
||||
ERROR: stride cannot equal zero
|
||||
-- Test casting within a BETWEEN qualifier
|
||||
SELECT d1 - timestamp with time zone '1997-01-02' AS diff
|
||||
FROM TIMESTAMPTZ_TBL
|
||||
|
@ -263,6 +263,9 @@ SELECT date_bin('5 min'::interval, timestamp '2020-02-01 01:01:01', timestamp '2
|
||||
SELECT date_bin('5 months'::interval, timestamp '2020-02-01 01:01:01', timestamp '2001-01-01');
|
||||
SELECT date_bin('5 years'::interval, timestamp '2020-02-01 01:01:01', timestamp '2001-01-01');
|
||||
|
||||
-- disallow zero intervals
|
||||
SELECT date_bin('0 days'::interval, timestamp '1970-01-01 01:00:00' , timestamp '1970-01-01 00:00:00');
|
||||
|
||||
-- Test casting within a BETWEEN qualifier
|
||||
SELECT d1 - timestamp without time zone '1997-01-02' AS diff
|
||||
FROM TIMESTAMP_TBL
|
||||
|
@ -238,6 +238,9 @@ SELECT date_bin('5 min'::interval, timestamptz '2020-02-01 01:01:01+00', timesta
|
||||
SELECT date_bin('5 months'::interval, timestamp with time zone '2020-02-01 01:01:01+00', timestamp with time zone '2001-01-01+00');
|
||||
SELECT date_bin('5 years'::interval, timestamp with time zone '2020-02-01 01:01:01+00', timestamp with time zone '2001-01-01+00');
|
||||
|
||||
-- disallow zero intervals
|
||||
SELECT date_bin('0 days'::interval, timestamp with time zone '1970-01-01 01:00:00+00' , timestamp with time zone '1970-01-01 00:00:00+00');
|
||||
|
||||
-- Test casting within a BETWEEN qualifier
|
||||
SELECT d1 - timestamp with time zone '1997-01-02' AS diff
|
||||
FROM TIMESTAMPTZ_TBL
|
||||
|
Loading…
x
Reference in New Issue
Block a user