1
0
mirror of https://github.com/postgres/postgres.git synced 2025-06-14 18:42:34 +03:00

Disallow negative strides in date_bin()

It's not clear what the semantics of negative strides would be, so throw
an error instead.

Per report from Bauyrzhan Sakhariyev

Reviewed-by: Tom Lane, Michael Paquier
Discussion: https://www.postgresql.org/message-id/CAKpL73vZmLuFVuwF26FJ%2BNk11PVHhAnQRoREFcA03x7znRoFvA%40mail.gmail.com
Backpatch to v14
This commit is contained in:
John Naylor
2021-07-28 11:22:58 -04:00
parent ed1884a2fe
commit 3ba70d4e15
6 changed files with 20 additions and 12 deletions

View File

@ -3843,10 +3843,10 @@ timestamp_bin(PG_FUNCTION_ARGS)
stride_usecs = stride->day * USECS_PER_DAY + stride->time;
if (stride_usecs == 0)
if (stride_usecs <= 0)
ereport(ERROR,
(errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
errmsg("stride cannot equal zero")));
errmsg("stride must be greater than zero")));
tm_diff = timestamp - origin;
tm_delta = tm_diff - tm_diff % stride_usecs;
@ -4026,10 +4026,10 @@ timestamptz_bin(PG_FUNCTION_ARGS)
stride_usecs = stride->day * USECS_PER_DAY + stride->time;
if (stride_usecs == 0)
if (stride_usecs <= 0)
ereport(ERROR,
(errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
errmsg("stride cannot equal zero")));
errmsg("stride must be greater than zero")));
tm_diff = timestamp - origin;
tm_delta = tm_diff - tm_diff % stride_usecs;