Skip to content

Commit 572c0f1

Browse files
committed
Improve tests of date_trunc() with infinity and unsupported units
Commit d85ce01 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 d85ce01. 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 d85ce01. 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 2242b26, 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
1 parent 2242b26 commit 572c0f1

File tree

4 files changed

+36
-3
lines changed

4 files changed

+36
-3
lines changed

src/test/regress/expected/timestamp.out

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -591,6 +591,16 @@ SELECT date_trunc( 'week', timestamp '2004-02-29 15:44:17.71393' ) AS week_trunc
591591
Mon Feb 23 00:00:00 2004
592592
(1 row)
593593

594+
SELECT date_trunc( 'week', timestamp 'infinity' ) AS inf_trunc;
595+
inf_trunc
596+
-----------
597+
infinity
598+
(1 row)
599+
600+
SELECT date_trunc( 'timezone', timestamp '2004-02-29 15:44:17.71393' ) AS notsupp_trunc;
601+
ERROR: unit "timezone" not supported for type timestamp without time zone
602+
SELECT date_trunc( 'timezone', timestamp 'infinity' ) AS notsupp_inf_trunc;
603+
ERROR: unit "timezone" not supported for type timestamp without time zone
594604
SELECT date_trunc( 'ago', timestamp 'infinity' ) AS invalid_trunc;
595605
ERROR: unit "ago" not recognized for type timestamp without time zone
596606
-- verify date_bin behaves the same as date_trunc for relevant intervals

src/test/regress/expected/timestamptz.out

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -760,6 +760,16 @@ SELECT date_trunc( 'week', timestamp with time zone '2004-02-29 15:44:17.71393'
760760
Mon Feb 23 00:00:00 2004 PST
761761
(1 row)
762762

763+
SELECT date_trunc( 'week', timestamp with time zone 'infinity' ) AS inf_trunc;
764+
inf_trunc
765+
-----------
766+
infinity
767+
(1 row)
768+
769+
SELECT date_trunc( 'timezone', timestamp with time zone '2004-02-29 15:44:17.71393' ) AS notsupp_trunc;
770+
ERROR: unit "timezone" not supported for type timestamp with time zone
771+
SELECT date_trunc( 'timezone', timestamp with time zone 'infinity' ) AS notsupp_inf_trunc;
772+
ERROR: unit "timezone" not supported for type timestamp with time zone
763773
SELECT date_trunc( 'ago', timestamp with time zone 'infinity' ) AS invalid_trunc;
764774
ERROR: unit "ago" not recognized for type timestamp with time zone
765775
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
780790
Thu Feb 15 20:00:00 2001 PST
781791
(1 row)
782792

793+
SELECT date_trunc('timezone', timestamp with time zone 'infinity', 'GMT') AS notsupp_zone_trunc;
794+
ERROR: unit "timezone" not supported for type timestamp with time zone
795+
SELECT date_trunc( 'week', timestamp with time zone 'infinity', 'GMT') AS inf_zone_trunc;
796+
inf_zone_trunc
797+
----------------
798+
infinity
799+
(1 row)
800+
783801
SELECT date_trunc('ago', timestamp with time zone 'infinity', 'GMT') AS invalid_zone_trunc;
784802
ERROR: unit "ago" not recognized for type timestamp with time zone
785803
-- verify date_bin behaves the same as date_trunc for relevant intervals

src/test/regress/sql/timestamp.sql

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,9 @@ SELECT d1 - timestamp without time zone '1997-01-02' AS diff
175175
FROM TIMESTAMP_TBL WHERE d1 BETWEEN '1902-01-01' AND '2038-01-01';
176176

177177
SELECT date_trunc( 'week', timestamp '2004-02-29 15:44:17.71393' ) AS week_trunc;
178-
178+
SELECT date_trunc( 'week', timestamp 'infinity' ) AS inf_trunc;
179+
SELECT date_trunc( 'timezone', timestamp '2004-02-29 15:44:17.71393' ) AS notsupp_trunc;
180+
SELECT date_trunc( 'timezone', timestamp 'infinity' ) AS notsupp_inf_trunc;
179181
SELECT date_trunc( 'ago', timestamp 'infinity' ) AS invalid_trunc;
180182

181183
-- verify date_bin behaves the same as date_trunc for relevant intervals

src/test/regress/sql/timestamptz.sql

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -217,15 +217,18 @@ SELECT d1 - timestamp with time zone '1997-01-02' AS diff
217217
FROM TIMESTAMPTZ_TBL WHERE d1 BETWEEN '1902-01-01' AND '2038-01-01';
218218

219219
SELECT date_trunc( 'week', timestamp with time zone '2004-02-29 15:44:17.71393' ) AS week_trunc;
220+
SELECT date_trunc( 'week', timestamp with time zone 'infinity' ) AS inf_trunc;
221+
SELECT date_trunc( 'timezone', timestamp with time zone '2004-02-29 15:44:17.71393' ) AS notsupp_trunc;
222+
SELECT date_trunc( 'timezone', timestamp with time zone 'infinity' ) AS notsupp_inf_trunc;
220223
SELECT date_trunc( 'ago', timestamp with time zone 'infinity' ) AS invalid_trunc;
221224

222225
SELECT date_trunc('day', timestamp with time zone '2001-02-16 20:38:40+00', 'Australia/Sydney') as sydney_trunc; -- zone name
223226
SELECT date_trunc('day', timestamp with time zone '2001-02-16 20:38:40+00', 'GMT') as gmt_trunc; -- fixed-offset abbreviation
224227
SELECT date_trunc('day', timestamp with time zone '2001-02-16 20:38:40+00', 'VET') as vet_trunc; -- variable-offset abbreviation
228+
SELECT date_trunc('timezone', timestamp with time zone 'infinity', 'GMT') AS notsupp_zone_trunc;
229+
SELECT date_trunc( 'week', timestamp with time zone 'infinity', 'GMT') AS inf_zone_trunc;
225230
SELECT date_trunc('ago', timestamp with time zone 'infinity', 'GMT') AS invalid_zone_trunc;
226231

227-
228-
229232
-- verify date_bin behaves the same as date_trunc for relevant intervals
230233
SELECT
231234
str,

0 commit comments

Comments
 (0)