mirror of
https://github.com/postgres/postgres.git
synced 2025-09-03 15:22:11 +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:
@@ -706,7 +706,10 @@ SELECT date_bin('5 years'::interval, timestamp '2020-02-01 01:01:01', timestamp
|
||||
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
|
||||
ERROR: stride must be greater than zero
|
||||
-- disallow negative intervals
|
||||
SELECT date_bin('-2 days'::interval, timestamp '1970-01-01 01:00:00' , timestamp '1970-01-01 00:00:00');
|
||||
ERROR: stride must be greater than zero
|
||||
-- Test casting within a BETWEEN qualifier
|
||||
SELECT d1 - timestamp without time zone '1997-01-02' AS diff
|
||||
FROM TIMESTAMP_TBL
|
||||
|
@@ -750,7 +750,10 @@ SELECT date_bin('5 years'::interval, timestamp with time zone '2020-02-01 01:01
|
||||
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
|
||||
ERROR: stride must be greater than zero
|
||||
-- disallow negative intervals
|
||||
SELECT date_bin('-2 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 must be greater than zero
|
||||
-- Test casting within a BETWEEN qualifier
|
||||
SELECT d1 - timestamp with time zone '1997-01-02' AS diff
|
||||
FROM TIMESTAMPTZ_TBL
|
||||
|
@@ -266,6 +266,9 @@ SELECT date_bin('5 years'::interval, timestamp '2020-02-01 01:01:01', timestamp
|
||||
-- disallow zero intervals
|
||||
SELECT date_bin('0 days'::interval, timestamp '1970-01-01 01:00:00' , timestamp '1970-01-01 00:00:00');
|
||||
|
||||
-- disallow negative intervals
|
||||
SELECT date_bin('-2 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
|
||||
|
@@ -241,6 +241,9 @@ SELECT date_bin('5 years'::interval, timestamp with time zone '2020-02-01 01:01
|
||||
-- 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');
|
||||
|
||||
-- disallow negative intervals
|
||||
SELECT date_bin('-2 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
|
||||
|
Reference in New Issue
Block a user