aboutsummaryrefslogtreecommitdiff
path: root/src/backend/utils/adt/timestamp.c
diff options
context:
space:
mode:
authorJohn Naylor <john.naylor@postgresql.org>2021-07-28 11:22:58 -0400
committerJohn Naylor <john.naylor@postgresql.org>2021-07-28 12:10:12 -0400
commit3ba70d4e152372fd8ab90ed0887ee08d505ef306 (patch)
tree0a9f052ccd6bf9a23b55442e512c4c5b19e0699c /src/backend/utils/adt/timestamp.c
parented1884a2fedeffd2e6902451a9d41f4b3f6e859f (diff)
downloadpostgresql-3ba70d4e152372fd8ab90ed0887ee08d505ef306.tar.gz
postgresql-3ba70d4e152372fd8ab90ed0887ee08d505ef306.zip
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
Diffstat (limited to 'src/backend/utils/adt/timestamp.c')
-rw-r--r--src/backend/utils/adt/timestamp.c8
1 files changed, 4 insertions, 4 deletions
diff --git a/src/backend/utils/adt/timestamp.c b/src/backend/utils/adt/timestamp.c
index ea847576cd2..1c0bf0aa5c8 100644
--- a/src/backend/utils/adt/timestamp.c
+++ b/src/backend/utils/adt/timestamp.c
@@ -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;