Skip to content

Commit 20ce873

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 1130206 commit 20ce873

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
@@ -7616,10 +7616,11 @@ SELECT date_trunc('year', TIMESTAMP '2001-02-16 20:38:40');
76167616
</indexterm>
76177617

76187618
<para>
7619-
The <literal>AT TIME ZONE</literal> construct allows conversions
7620-
of time stamps to different time zones. <xref
7621-
linkend="functions-datetime-zoneconvert-table"> shows its
7622-
variants.
7619+
The <literal>AT TIME ZONE</literal> converts time
7620+
stamp <emphasis>without time zone</emphasis> to/from
7621+
time stamp <emphasis>with time zone</emphasis>, and
7622+
<emphasis>time</emphasis> values to different time zones. <xref
7623+
linkend="functions-datetime-zoneconvert-table"> shows its variants.
76237624
</para>
76247625

76257626
<table id="functions-datetime-zoneconvert-table">
@@ -7664,24 +7665,33 @@ SELECT date_trunc('year', TIMESTAMP '2001-02-16 20:38:40');
76647665

76657666
<para>
76667667
In these expressions, the desired time zone <replaceable>zone</> can be
7667-
specified either as a text string (e.g., <literal>'PST'</literal>)
7668+
specified either as a text string (e.g., <literal>'America/Los_Angeles'</literal>)
76687669
or as an interval (e.g., <literal>INTERVAL '-08:00'</literal>).
76697670
In the text case, a time zone name can be specified in any of the ways
76707671
described in <xref linkend="datatype-timezones">.
76717672
</para>
76727673

76737674
<para>
7674-
Examples (assuming the local time zone is <literal>PST8PDT</>):
7675+
Examples (assuming the local time zone is <literal>America/Los_Angeles</literal>):
76757676
<screen>
7676-
SELECT TIMESTAMP '2001-02-16 20:38:40' AT TIME ZONE 'MST';
7677+
SELECT TIMESTAMP '2001-02-16 20:38:40' AT TIME ZONE 'America/Denver';
76777678
<lineannotation>Result: </lineannotation><computeroutput>2001-02-16 19:38:40-08</computeroutput>
76787679

7679-
SELECT TIMESTAMP WITH TIME ZONE '2001-02-16 20:38:40-05' AT TIME ZONE 'MST';
7680+
SELECT TIMESTAMP WITH TIME ZONE '2001-02-16 20:38:40-05' AT TIME ZONE 'America/Denver';
76807681
<lineannotation>Result: </lineannotation><computeroutput>2001-02-16 18:38:40</computeroutput>
7682+
7683+
SELECT TIMESTAMP '2001-02-16 20:38:40-05' AT TIME ZONE 'Asia/Tokyo' AT TIME ZONE 'America/Chicago';
7684+
<lineannotation>Result: </lineannotation><computeroutput>2001-02-16 05:38:40</computeroutput>
76817685
</screen>
7682-
The first example takes a time stamp without time zone and interprets it as MST time
7683-
(UTC-7), which is then converted to PST (UTC-8) for display. The second example takes
7684-
a time stamp specified in EST (UTC-5) and converts it to local time in MST (UTC-7).
7686+
The first example adds a time zone to a value that lacks it, and
7687+
displays the value using the current <varname>TimeZone</varname>
7688+
setting. The second example shifts the time stamp with time zone value
7689+
to the specified time zone, and returns the value without a time zone.
7690+
This allows storage and display of values different from the current
7691+
<varname>TimeZone</varname> setting. The third example converts
7692+
Tokyo time to Chicago time. Converting <emphasis>time</emphasis>
7693+
values to other time zones uses the currently active time zone rules
7694+
since no date is supplied.
76857695
</para>
76867696

76877697
<para>

0 commit comments

Comments
 (0)