Received: from malur.postgresql.org ([2a02:16a8:dc51::56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fwomb-0000Jt-8e for pgsql-docs@arkaria.postgresql.org; Mon, 03 Sep 2018 13:20:45 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1fwomY-0008Ie-Mt for pgsql-docs@arkaria.postgresql.org; Mon, 03 Sep 2018 13:20:42 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fwomY-0008IW-DE for pgsql-docs@lists.postgresql.org; Mon, 03 Sep 2018 13:20:42 +0000 Received: from momjian.us ([72.94.173.45]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1fwomR-0005oH-BL for pgsql-docs@postgresql.org; Mon, 03 Sep 2018 13:20:41 +0000 Received: from bruce by momjian.us with local (Exim 4.84_2) (envelope-from ) id 1fwomQ-00013w-7Z; Mon, 03 Sep 2018 09:20:34 -0400 Date: Mon, 3 Sep 2018 09:20:34 -0400 From: Bruce Momjian To: Tom Lane Cc: PostgreSQL-documentation Subject: Re: AT TIME ZONE correction Message-ID: <20180903132034.GD25700@momjian.us> References: <20180901225557.GA22406@momjian.us> <24277.1535844643@sss.pgh.pa.us> <20180901233736.GA25700@momjian.us> <20180902032821.GB25700@momjian.us> <14024.1535912518@sss.pgh.pa.us> <20180903021159.GC25700@momjian.us> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="8X7/QrJGcKSMr1RN" Content-Disposition: inline In-Reply-To: <20180903021159.GC25700@momjian.us> User-Agent: Mutt/1.5.23 (2014-03-12) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk --8X7/QrJGcKSMr1RN Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On Sun, Sep 2, 2018 at 10:11:59PM -0400, Bruce Momjian wrote: > On Sun, Sep 2, 2018 at 02:21:58PM -0400, Tom Lane wrote: > > I still find this to be more confusing than helpful. In particular, > > I do not think that it's possible to explain this behavior clearly > > without mentioning that timestamp with time zone values are always > > stored in UTC and what AT TIME ZONE really does is convert between UTC > > and the specified zone (in a direction dependent on which type is > > supplied as argument). > > Agreed. The more I dig into this the more I learn. I have developed > the attached patch which I hope this time is an improvement. I polished the text some more and changed the three-letter time zone abbreviation (e.g., MST) to use the more general text, e.g. "America/Denver". We should not be encouraging people to specify the daylight savings time status based on the date in the date/time string. -- Bruce Momjian http://momjian.us EnterpriseDB http://enterprisedb.com + As you are, so once was I. As I am, so you will be. + + Ancient Roman grave inscription + --8X7/QrJGcKSMr1RN Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="time_zone.diff" diff --git a/doc/src/sgml/func.sgml b/doc/src/sgml/func.sgml index bb794e0..2135799 100644 --- a/doc/src/sgml/func.sgml +++ b/doc/src/sgml/func.sgml @@ -8082,10 +8082,11 @@ SELECT date_trunc('year', TIMESTAMP '2001-02-16 20:38:40'); - The AT TIME ZONE construct allows conversions - of time stamps to different time zones. shows its - variants. + The AT TIME ZONE converts time + stamp without time zone to/from + time stamp with time zone, and + time values to different time zones. shows its variants. @@ -8130,24 +8131,29 @@ SELECT date_trunc('year', TIMESTAMP '2001-02-16 20:38:40'); In these expressions, the desired time zone zone can be - specified either as a text string (e.g., 'PST') + specified either as a text string (e.g., 'America/Los_Angeles') or as an interval (e.g., INTERVAL '-08:00'). In the text case, a time zone name can be specified in any of the ways described in . - Examples (assuming the local time zone is PST8PDT): + Examples (assuming the local time zone is America/Los_Angeles): -SELECT TIMESTAMP '2001-02-16 20:38:40' AT TIME ZONE 'MST'; +SELECT TIMESTAMP '2001-02-16 20:38:40' AT TIME ZONE 'America/Denver'; Result: 2001-02-16 19:38:40-08 -SELECT TIMESTAMP WITH TIME ZONE '2001-02-16 20:38:40-05' AT TIME ZONE 'MST'; +SELECT TIMESTAMP WITH TIME ZONE '2001-02-16 20:38:40-05' AT TIME ZONE 'America/Denver'; Result: 2001-02-16 18:38:40 - The first example takes a time stamp without time zone and interprets it as MST time - (UTC-7), which is then converted to PST (UTC-8) for display. The second example takes - a time stamp specified in EST (UTC-5) and converts it to local time in MST (UTC-7). + The first example adds a time zone to a value that lacks it, and + displays the value using the current TimeZone + setting. The second example shifts the time stamp with time zone + value to the specified time zone, and returns the value without a + time zone. This allows storage and display of values different + from the current TimeZone setting. Converting + time values to other time zones uses the currently + active time zone rules since no date is supplied. --8X7/QrJGcKSMr1RN--