mirror of
https://github.com/postgres/postgres.git
synced 2025-07-14 08:21:07 +03:00
Add a timezone-specific variant of date_trunc().
date_trunc(field, timestamptz, zone_name) performs truncation using the named time zone as reference, rather than working in the session time zone as is the default behavior. It's equivalent to date_trunc(field, timestamptz at time zone zone_name) at time zone zone_name but it's faster, easier to type, and arguably easier to understand. Vik Fearing and Tom Lane Discussion: https://postgr.es/m/6249ffc4-2b22-4c1b-4e7d-7af84fedd7c6@2ndquadrant.com
This commit is contained in:
@ -649,6 +649,24 @@ SELECT '' AS date_trunc_week, date_trunc( 'week', timestamp with time zone '2004
|
||||
| Mon Feb 23 00:00:00 2004 PST
|
||||
(1 row)
|
||||
|
||||
SELECT '' AS date_trunc_at_tz, date_trunc('day', timestamp with time zone '2001-02-16 20:38:40+00', 'Australia/Sydney') as sydney_trunc; -- zone name
|
||||
date_trunc_at_tz | sydney_trunc
|
||||
------------------+------------------------------
|
||||
| Fri Feb 16 05:00:00 2001 PST
|
||||
(1 row)
|
||||
|
||||
SELECT '' AS date_trunc_at_tz, date_trunc('day', timestamp with time zone '2001-02-16 20:38:40+00', 'GMT') as gmt_trunc; -- fixed-offset abbreviation
|
||||
date_trunc_at_tz | gmt_trunc
|
||||
------------------+------------------------------
|
||||
| Thu Feb 15 16:00:00 2001 PST
|
||||
(1 row)
|
||||
|
||||
SELECT '' AS date_trunc_at_tz, date_trunc('day', timestamp with time zone '2001-02-16 20:38:40+00', 'VET') as vet_trunc; -- variable-offset abbreviation
|
||||
date_trunc_at_tz | vet_trunc
|
||||
------------------+------------------------------
|
||||
| Thu Feb 15 20:00:00 2001 PST
|
||||
(1 row)
|
||||
|
||||
-- Test casting within a BETWEEN qualifier
|
||||
SELECT '' AS "54", d1 - timestamp with time zone '1997-01-02' AS diff
|
||||
FROM TIMESTAMPTZ_TBL
|
||||
|
@ -193,6 +193,10 @@ SELECT '' AS "54", d1 - timestamp with time zone '1997-01-02' AS diff
|
||||
|
||||
SELECT '' AS date_trunc_week, date_trunc( 'week', timestamp with time zone '2004-02-29 15:44:17.71393' ) AS week_trunc;
|
||||
|
||||
SELECT '' AS date_trunc_at_tz, date_trunc('day', timestamp with time zone '2001-02-16 20:38:40+00', 'Australia/Sydney') as sydney_trunc; -- zone name
|
||||
SELECT '' AS date_trunc_at_tz, date_trunc('day', timestamp with time zone '2001-02-16 20:38:40+00', 'GMT') as gmt_trunc; -- fixed-offset abbreviation
|
||||
SELECT '' AS date_trunc_at_tz, date_trunc('day', timestamp with time zone '2001-02-16 20:38:40+00', 'VET') as vet_trunc; -- variable-offset abbreviation
|
||||
|
||||
-- Test casting within a BETWEEN qualifier
|
||||
SELECT '' AS "54", d1 - timestamp with time zone '1997-01-02' AS diff
|
||||
FROM TIMESTAMPTZ_TBL
|
||||
|
Reference in New Issue
Block a user