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 <br...@momjian.us> 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 +
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'); </indexterm> <para> - The <literal>AT TIME ZONE</literal> construct allows conversions - of time stamps to different time zones. <xref - linkend="functions-datetime-zoneconvert-table"/> shows its - variants. + The <literal>AT TIME ZONE</literal> converts time + stamp <emphasis>without time zone</emphasis> to/from + time stamp <emphasis>with time zone</emphasis>, and + <emphasis>time</emphasis> values to different time zones. <xref + linkend="functions-datetime-zoneconvert-table"/> shows its variants. </para> <table id="functions-datetime-zoneconvert-table"> @@ -8130,24 +8131,29 @@ SELECT date_trunc('year', TIMESTAMP '2001-02-16 20:38:40'); <para> In these expressions, the desired time zone <replaceable>zone</replaceable> can be - specified either as a text string (e.g., <literal>'PST'</literal>) + specified either as a text string (e.g., <literal>'America/Los_Angeles'</literal>) or as an interval (e.g., <literal>INTERVAL '-08:00'</literal>). In the text case, a time zone name can be specified in any of the ways described in <xref linkend="datatype-timezones"/>. </para> <para> - Examples (assuming the local time zone is <literal>PST8PDT</literal>): + Examples (assuming the local time zone is <literal>America/Los_Angeles</literal>): <screen> -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'; <lineannotation>Result: </lineannotation><computeroutput>2001-02-16 19:38:40-08</computeroutput> -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'; <lineannotation>Result: </lineannotation><computeroutput>2001-02-16 18:38:40</computeroutput> </screen> - 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 <varname>TimeZone</varname> + 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 <varname>TimeZone</varname> setting. Converting + <emphasis>time</emphasis> values to other time zones uses the currently + active time zone rules since no date is supplied. </para> <para>