1
0
mirror of https://github.com/postgres/postgres.git synced 2025-08-28 18:48:04 +03:00

Fix division by zero error in date_bin

Bauyrzhan Sakhariyev, via Github

Backpatch to v14
This commit is contained in:
John Naylor
2021-07-22 17:34:19 -04:00
parent 86a1aae764
commit a0db4294ae
5 changed files with 22 additions and 0 deletions

View File

@@ -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;