mirror of
https://github.com/postgres/postgres.git
synced 2025-10-09 00:05:07 -04:00
Improve tests of date_trunc() with infinity and unsupported units
Commit d85ce012f99f has added some new error handling code to date_trunc() of timestamp, timestamptz, and interval with infinite values. However, the new test cases added by that commit did not actually test all of the new code, missing coverage for the following cases: 1) For timestamp without time zone: 1-1) infinite value with valid unit 1-2) infinite value with unsupported unit 1-3) finite value with unsupported unit, for a code path older than d85ce012f99f. 2) For timestamp with time zone, without a time zone specified for the truncation: 2-1) infinite value with valid unit 2-2) infinite value with unsupported unit 2-3) finite value with unsupported unit, for a code path older than d85ce012f99f. 3) For timestamp with time zone, with a time zone specified for the truncation: 3-1) infinite value with valid unit. 3-2) infinite value with unsupported unit. This commit also provides coverage for the bug fixed in 2242b26ce472, through cases 2-1) and 3-1), when using an infinite value with a valid unit, with[out] the optional time zone parameter used for the truncation. Author: Peter Eisentraut <peter@eisentraut.org> Discussion: https://postgr.es/m/2d320b6f-b4af-4fbc-9eec-5d0fa15d187b@eisentraut.org Discussion: https://postgr.es/m/4bf60a84-2862-4a53-acd5-8eddf134a60e@eisentraut.org Backpatch-through: 18
This commit is contained in:
parent
2242b26ce4
commit
572c0f1b0e
@ -591,6 +591,16 @@ SELECT date_trunc( 'week', timestamp '2004-02-29 15:44:17.71393' ) AS week_trunc
|
|||||||
Mon Feb 23 00:00:00 2004
|
Mon Feb 23 00:00:00 2004
|
||||||
(1 row)
|
(1 row)
|
||||||
|
|
||||||
|
SELECT date_trunc( 'week', timestamp 'infinity' ) AS inf_trunc;
|
||||||
|
inf_trunc
|
||||||
|
-----------
|
||||||
|
infinity
|
||||||
|
(1 row)
|
||||||
|
|
||||||
|
SELECT date_trunc( 'timezone', timestamp '2004-02-29 15:44:17.71393' ) AS notsupp_trunc;
|
||||||
|
ERROR: unit "timezone" not supported for type timestamp without time zone
|
||||||
|
SELECT date_trunc( 'timezone', timestamp 'infinity' ) AS notsupp_inf_trunc;
|
||||||
|
ERROR: unit "timezone" not supported for type timestamp without time zone
|
||||||
SELECT date_trunc( 'ago', timestamp 'infinity' ) AS invalid_trunc;
|
SELECT date_trunc( 'ago', timestamp 'infinity' ) AS invalid_trunc;
|
||||||
ERROR: unit "ago" not recognized for type timestamp without time zone
|
ERROR: unit "ago" not recognized for type timestamp without time zone
|
||||||
-- verify date_bin behaves the same as date_trunc for relevant intervals
|
-- verify date_bin behaves the same as date_trunc for relevant intervals
|
||||||
|
@ -760,6 +760,16 @@ SELECT date_trunc( 'week', timestamp with time zone '2004-02-29 15:44:17.71393'
|
|||||||
Mon Feb 23 00:00:00 2004 PST
|
Mon Feb 23 00:00:00 2004 PST
|
||||||
(1 row)
|
(1 row)
|
||||||
|
|
||||||
|
SELECT date_trunc( 'week', timestamp with time zone 'infinity' ) AS inf_trunc;
|
||||||
|
inf_trunc
|
||||||
|
-----------
|
||||||
|
infinity
|
||||||
|
(1 row)
|
||||||
|
|
||||||
|
SELECT date_trunc( 'timezone', timestamp with time zone '2004-02-29 15:44:17.71393' ) AS notsupp_trunc;
|
||||||
|
ERROR: unit "timezone" not supported for type timestamp with time zone
|
||||||
|
SELECT date_trunc( 'timezone', timestamp with time zone 'infinity' ) AS notsupp_inf_trunc;
|
||||||
|
ERROR: unit "timezone" not supported for type timestamp with time zone
|
||||||
SELECT date_trunc( 'ago', timestamp with time zone 'infinity' ) AS invalid_trunc;
|
SELECT date_trunc( 'ago', timestamp with time zone 'infinity' ) AS invalid_trunc;
|
||||||
ERROR: unit "ago" not recognized for type timestamp with time zone
|
ERROR: unit "ago" not recognized for type timestamp with time zone
|
||||||
SELECT date_trunc('day', timestamp with time zone '2001-02-16 20:38:40+00', 'Australia/Sydney') as sydney_trunc; -- zone name
|
SELECT date_trunc('day', timestamp with time zone '2001-02-16 20:38:40+00', 'Australia/Sydney') as sydney_trunc; -- zone name
|
||||||
@ -780,6 +790,14 @@ SELECT date_trunc('day', timestamp with time zone '2001-02-16 20:38:40+00', 'VET
|
|||||||
Thu Feb 15 20:00:00 2001 PST
|
Thu Feb 15 20:00:00 2001 PST
|
||||||
(1 row)
|
(1 row)
|
||||||
|
|
||||||
|
SELECT date_trunc('timezone', timestamp with time zone 'infinity', 'GMT') AS notsupp_zone_trunc;
|
||||||
|
ERROR: unit "timezone" not supported for type timestamp with time zone
|
||||||
|
SELECT date_trunc( 'week', timestamp with time zone 'infinity', 'GMT') AS inf_zone_trunc;
|
||||||
|
inf_zone_trunc
|
||||||
|
----------------
|
||||||
|
infinity
|
||||||
|
(1 row)
|
||||||
|
|
||||||
SELECT date_trunc('ago', timestamp with time zone 'infinity', 'GMT') AS invalid_zone_trunc;
|
SELECT date_trunc('ago', timestamp with time zone 'infinity', 'GMT') AS invalid_zone_trunc;
|
||||||
ERROR: unit "ago" not recognized for type timestamp with time zone
|
ERROR: unit "ago" not recognized for type timestamp with time zone
|
||||||
-- verify date_bin behaves the same as date_trunc for relevant intervals
|
-- verify date_bin behaves the same as date_trunc for relevant intervals
|
||||||
|
@ -175,7 +175,9 @@ SELECT d1 - timestamp without time zone '1997-01-02' AS diff
|
|||||||
FROM TIMESTAMP_TBL WHERE d1 BETWEEN '1902-01-01' AND '2038-01-01';
|
FROM TIMESTAMP_TBL WHERE d1 BETWEEN '1902-01-01' AND '2038-01-01';
|
||||||
|
|
||||||
SELECT date_trunc( 'week', timestamp '2004-02-29 15:44:17.71393' ) AS week_trunc;
|
SELECT date_trunc( 'week', timestamp '2004-02-29 15:44:17.71393' ) AS week_trunc;
|
||||||
|
SELECT date_trunc( 'week', timestamp 'infinity' ) AS inf_trunc;
|
||||||
|
SELECT date_trunc( 'timezone', timestamp '2004-02-29 15:44:17.71393' ) AS notsupp_trunc;
|
||||||
|
SELECT date_trunc( 'timezone', timestamp 'infinity' ) AS notsupp_inf_trunc;
|
||||||
SELECT date_trunc( 'ago', timestamp 'infinity' ) AS invalid_trunc;
|
SELECT date_trunc( 'ago', timestamp 'infinity' ) AS invalid_trunc;
|
||||||
|
|
||||||
-- verify date_bin behaves the same as date_trunc for relevant intervals
|
-- verify date_bin behaves the same as date_trunc for relevant intervals
|
||||||
|
@ -217,15 +217,18 @@ SELECT d1 - timestamp with time zone '1997-01-02' AS diff
|
|||||||
FROM TIMESTAMPTZ_TBL WHERE d1 BETWEEN '1902-01-01' AND '2038-01-01';
|
FROM TIMESTAMPTZ_TBL WHERE d1 BETWEEN '1902-01-01' AND '2038-01-01';
|
||||||
|
|
||||||
SELECT date_trunc( 'week', timestamp with time zone '2004-02-29 15:44:17.71393' ) AS week_trunc;
|
SELECT date_trunc( 'week', timestamp with time zone '2004-02-29 15:44:17.71393' ) AS week_trunc;
|
||||||
|
SELECT date_trunc( 'week', timestamp with time zone 'infinity' ) AS inf_trunc;
|
||||||
|
SELECT date_trunc( 'timezone', timestamp with time zone '2004-02-29 15:44:17.71393' ) AS notsupp_trunc;
|
||||||
|
SELECT date_trunc( 'timezone', timestamp with time zone 'infinity' ) AS notsupp_inf_trunc;
|
||||||
SELECT date_trunc( 'ago', timestamp with time zone 'infinity' ) AS invalid_trunc;
|
SELECT date_trunc( 'ago', timestamp with time zone 'infinity' ) AS invalid_trunc;
|
||||||
|
|
||||||
SELECT date_trunc('day', timestamp with time zone '2001-02-16 20:38:40+00', 'Australia/Sydney') as sydney_trunc; -- zone name
|
SELECT date_trunc('day', timestamp with time zone '2001-02-16 20:38:40+00', 'Australia/Sydney') as sydney_trunc; -- zone name
|
||||||
SELECT date_trunc('day', timestamp with time zone '2001-02-16 20:38:40+00', 'GMT') as gmt_trunc; -- fixed-offset abbreviation
|
SELECT date_trunc('day', timestamp with time zone '2001-02-16 20:38:40+00', 'GMT') as gmt_trunc; -- fixed-offset abbreviation
|
||||||
SELECT date_trunc('day', timestamp with time zone '2001-02-16 20:38:40+00', 'VET') as vet_trunc; -- variable-offset abbreviation
|
SELECT date_trunc('day', timestamp with time zone '2001-02-16 20:38:40+00', 'VET') as vet_trunc; -- variable-offset abbreviation
|
||||||
|
SELECT date_trunc('timezone', timestamp with time zone 'infinity', 'GMT') AS notsupp_zone_trunc;
|
||||||
|
SELECT date_trunc( 'week', timestamp with time zone 'infinity', 'GMT') AS inf_zone_trunc;
|
||||||
SELECT date_trunc('ago', timestamp with time zone 'infinity', 'GMT') AS invalid_zone_trunc;
|
SELECT date_trunc('ago', timestamp with time zone 'infinity', 'GMT') AS invalid_zone_trunc;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
-- verify date_bin behaves the same as date_trunc for relevant intervals
|
-- verify date_bin behaves the same as date_trunc for relevant intervals
|
||||||
SELECT
|
SELECT
|
||||||
str,
|
str,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user