Skip to content

Commit b7156cf

Browse files
committed
docs: improve AT TIME ZONE description
The previous description was unclear. Also add a third example, change use of time zone acronyms to more verbose descriptions, and add a mention that using 'time' with AT TIME ZONE uses the current time zone rules. Backpatch-through: 9.3
1 parent bf61873 commit b7156cf

File tree

1 file changed

+21
-11
lines changed

1 file changed

+21
-11
lines changed

doc/src/sgml/func.sgml

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7963,10 +7963,11 @@ SELECT date_trunc('year', TIMESTAMP '2001-02-16 20:38:40');
79637963
</indexterm>
79647964

79657965
<para>
7966-
The <literal>AT TIME ZONE</literal> construct allows conversions
7967-
of time stamps to different time zones. <xref
7968-
linkend="functions-datetime-zoneconvert-table"> shows its
7969-
variants.
7966+
The <literal>AT TIME ZONE</literal> converts time
7967+
stamp <emphasis>without time zone</emphasis> to/from
7968+
time stamp <emphasis>with time zone</emphasis>, and
7969+
<emphasis>time</emphasis> values to different time zones. <xref
7970+
linkend="functions-datetime-zoneconvert-table"> shows its variants.
79707971
</para>
79717972

79727973
<table id="functions-datetime-zoneconvert-table">
@@ -8011,24 +8012,33 @@ SELECT date_trunc('year', TIMESTAMP '2001-02-16 20:38:40');
80118012

80128013
<para>
80138014
In these expressions, the desired time zone <replaceable>zone</> can be
8014-
specified either as a text string (e.g., <literal>'PST'</literal>)
8015+
specified either as a text string (e.g., <literal>'America/Los_Angeles'</literal>)
80158016
or as an interval (e.g., <literal>INTERVAL '-08:00'</literal>).
80168017
In the text case, a time zone name can be specified in any of the ways
80178018
described in <xref linkend="datatype-timezones">.
80188019
</para>
80198020

80208021
<para>
8021-
Examples (assuming the local time zone is <literal>PST8PDT</>):
8022+
Examples (assuming the local time zone is <literal>America/Los_Angeles</literal>):
80228023
<screen>
8023-
SELECT TIMESTAMP '2001-02-16 20:38:40' AT TIME ZONE 'MST';
8024+
SELECT TIMESTAMP '2001-02-16 20:38:40' AT TIME ZONE 'America/Denver';
80248025
<lineannotation>Result: </lineannotation><computeroutput>2001-02-16 19:38:40-08</computeroutput>
80258026

8026-
SELECT TIMESTAMP WITH TIME ZONE '2001-02-16 20:38:40-05' AT TIME ZONE 'MST';
8027+
SELECT TIMESTAMP WITH TIME ZONE '2001-02-16 20:38:40-05' AT TIME ZONE 'America/Denver';
80278028
<lineannotation>Result: </lineannotation><computeroutput>2001-02-16 18:38:40</computeroutput>
8029+
8030+
SELECT TIMESTAMP '2001-02-16 20:38:40-05' AT TIME ZONE 'Asia/Tokyo' AT TIME ZONE 'America/Chicago';
8031+
<lineannotation>Result: </lineannotation><computeroutput>2001-02-16 05:38:40</computeroutput>
80288032
</screen>
8029-
The first example takes a time stamp without time zone and interprets it as MST time
8030-
(UTC-7), which is then converted to PST (UTC-8) for display. The second example takes
8031-
a time stamp specified in EST (UTC-5) and converts it to local time in MST (UTC-7).
8033+
The first example adds a time zone to a value that lacks it, and
8034+
displays the value using the current <varname>TimeZone</varname>
8035+
setting. The second example shifts the time stamp with time zone value
8036+
to the specified time zone, and returns the value without a time zone.
8037+
This allows storage and display of values different from the current
8038+
<varname>TimeZone</varname> setting. The third example converts
8039+
Tokyo time to Chicago time. Converting <emphasis>time</emphasis>
8040+
values to other time zones uses the currently active time zone rules
8041+
since no date is supplied.
80328042
</para>
80338043

80348044
<para>

0 commit comments

Comments
 (0)