diff options
Diffstat (limited to 'src/backend/utils/adt/timestamp.c')
-rw-r--r-- | src/backend/utils/adt/timestamp.c | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/src/backend/utils/adt/timestamp.c b/src/backend/utils/adt/timestamp.c index b2bdbcab576..280ee7f92ba 100644 --- a/src/backend/utils/adt/timestamp.c +++ b/src/backend/utils/adt/timestamp.c @@ -3846,6 +3846,13 @@ timestamp_bin(PG_FUNCTION_ARGS) tm_diff = timestamp - origin; tm_delta = tm_diff - tm_diff % stride_usecs; + /* + * Make sure the returned timestamp is at the start of the bin, + * even if the origin is in the future. + */ + if (origin > timestamp && stride_usecs > 1) + tm_delta -= stride_usecs; + result = origin + tm_delta; PG_RETURN_TIMESTAMP(result); @@ -4017,6 +4024,13 @@ timestamptz_bin(PG_FUNCTION_ARGS) tm_diff = timestamp - origin; tm_delta = tm_diff - tm_diff % stride_usecs; + /* + * Make sure the returned timestamp is at the start of the bin, + * even if the origin is in the future. + */ + if (origin > timestamp && stride_usecs > 1) + tm_delta -= stride_usecs; + result = origin + tm_delta; PG_RETURN_TIMESTAMPTZ(result); |