Skip to content

Commit 630d445

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 0b50543 commit 630d445

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

74337433
<para>
7434-
The <literal>AT TIME ZONE</literal> construct allows conversions
7435-
of time stamps to different time zones. <xref
7436-
linkend="functions-datetime-zoneconvert-table"> shows its
7437-
variants.
7434+
The <literal>AT TIME ZONE</literal> converts time
7435+
stamp <emphasis>without time zone</emphasis> to/from
7436+
time stamp <emphasis>with time zone</emphasis>, and
7437+
<emphasis>time</emphasis> values to different time zones. <xref
7438+
linkend="functions-datetime-zoneconvert-table"> shows its variants.
74387439
</para>
74397440

74407441
<table id="functions-datetime-zoneconvert-table">
@@ -7479,24 +7480,33 @@ SELECT date_trunc('year', TIMESTAMP '2001-02-16 20:38:40');
74797480

74807481
<para>
74817482
In these expressions, the desired time zone <replaceable>zone</> can be
7482-
specified either as a text string (e.g., <literal>'PST'</literal>)
7483+
specified either as a text string (e.g., <literal>'America/Los_Angeles'</literal>)
74837484
or as an interval (e.g., <literal>INTERVAL '-08:00'</literal>).
74847485
In the text case, a time zone name can be specified in any of the ways
74857486
described in <xref linkend="datatype-timezones">.
74867487
</para>
74877488

74887489
<para>
7489-
Examples (assuming the local time zone is <literal>PST8PDT</>):
7490+
Examples (assuming the local time zone is <literal>America/Los_Angeles</literal>):
74907491
<screen>
7491-
SELECT TIMESTAMP '2001-02-16 20:38:40' AT TIME ZONE 'MST';
7492+
SELECT TIMESTAMP '2001-02-16 20:38:40' AT TIME ZONE 'America/Denver';
74927493
<lineannotation>Result: </lineannotation><computeroutput>2001-02-16 19:38:40-08</computeroutput>
74937494

7494-
SELECT TIMESTAMP WITH TIME ZONE '2001-02-16 20:38:40-05' AT TIME ZONE 'MST';
7495+
SELECT TIMESTAMP WITH TIME ZONE '2001-02-16 20:38:40-05' AT TIME ZONE 'America/Denver';
74957496
<lineannotation>Result: </lineannotation><computeroutput>2001-02-16 18:38:40</computeroutput>
7497+
7498+
SELECT TIMESTAMP '2001-02-16 20:38:40-05' AT TIME ZONE 'Asia/Tokyo' AT TIME ZONE 'America/Chicago';
7499+
<lineannotation>Result: </lineannotation><computeroutput>2001-02-16 05:38:40</computeroutput>
74967500
</screen>
7497-
The first example takes a time stamp without time zone and interprets it as MST time
7498-
(UTC-7), which is then converted to PST (UTC-8) for display. The second example takes
7499-
a time stamp specified in EST (UTC-5) and converts it to local time in MST (UTC-7).
7501+
The first example adds a time zone to a value that lacks it, and
7502+
displays the value using the current <varname>TimeZone</varname>
7503+
setting. The second example shifts the time stamp with time zone value
7504+
to the specified time zone, and returns the value without a time zone.
7505+
This allows storage and display of values different from the current
7506+
<varname>TimeZone</varname> setting. The third example converts
7507+
Tokyo time to Chicago time. Converting <emphasis>time</emphasis>
7508+
values to other time zones uses the currently active time zone rules
7509+
since no date is supplied.
75007510
</para>
75017511

75027512
<para>

0 commit comments

Comments
 (0)