@@ -10611,7 +10611,7 @@ SELECT date_bin('15 minutes', TIMESTAMP '2020-02-11 15:44:17', TIMESTAMP '2001-0
1061110611 </sect2>
1061210612
1061310613 <sect2 id="functions-datetime-zoneconvert">
10614- <title><literal>AT TIME ZONE</literal></title>
10614+ <title><literal>AT TIME ZONE and AT LOCAL </literal></title>
1061510615
1061610616 <indexterm>
1061710617 <primary>time zone</primary>
@@ -10622,6 +10622,10 @@ SELECT date_bin('15 minutes', TIMESTAMP '2020-02-11 15:44:17', TIMESTAMP '2001-0
1062210622 <primary>AT TIME ZONE</primary>
1062310623 </indexterm>
1062410624
10625+ <indexterm>
10626+ <primary>AT LOCAL</primary>
10627+ </indexterm>
10628+
1062510629 <para>
1062610630 The <literal>AT TIME ZONE</literal> operator converts time
1062710631 stamp <emphasis>without</emphasis> time zone to/from
@@ -10632,7 +10636,7 @@ SELECT date_bin('15 minutes', TIMESTAMP '2020-02-11 15:44:17', TIMESTAMP '2001-0
1063210636 </para>
1063310637
1063410638 <table id="functions-datetime-zoneconvert-table">
10635- <title><literal>AT TIME ZONE</literal> Variants</title>
10639+ <title><literal>AT TIME ZONE</literal> and <literal>AT LOCAL</literal> Variants</title>
1063610640 <tgroup cols="1">
1063710641 <thead>
1063810642 <row>
@@ -10665,6 +10669,22 @@ SELECT date_bin('15 minutes', TIMESTAMP '2020-02-11 15:44:17', TIMESTAMP '2001-0
1066510669 </para></entry>
1066610670 </row>
1066710671
10672+ <row>
10673+ <entry role="func_table_entry"><para role="func_signature">
10674+ <type>timestamp without time zone</type> <literal>AT LOCAL</literal>
10675+ <returnvalue>timestamp with time zone</returnvalue>
10676+ </para>
10677+ <para>
10678+ Converts given time stamp <emphasis>without</emphasis> time zone to
10679+ time stamp <emphasis>with</emphasis> the session's
10680+ <varname>TimeZone</varname> value as time zone.
10681+ </para>
10682+ <para>
10683+ <literal>timestamp '2001-02-16 20:38:40' at local</literal>
10684+ <returnvalue>2001-02-17 03:38:40+00</returnvalue>
10685+ </para></entry>
10686+ </row>
10687+
1066810688 <row>
1066910689 <entry role="func_table_entry"><para role="func_signature">
1067010690 <type>timestamp with time zone</type> <literal>AT TIME ZONE</literal> <replaceable>zone</replaceable>
@@ -10681,6 +10701,22 @@ SELECT date_bin('15 minutes', TIMESTAMP '2020-02-11 15:44:17', TIMESTAMP '2001-0
1068110701 </para></entry>
1068210702 </row>
1068310703
10704+ <row>
10705+ <entry role="func_table_entry"><para role="func_signature">
10706+ <type>timestamp with time zone</type> <literal>AT LOCAL</literal>
10707+ <returnvalue>timestamp without time zone</returnvalue>
10708+ </para>
10709+ <para>
10710+ Converts given time stamp <emphasis>with</emphasis> time zone to
10711+ time stamp <emphasis>without</emphasis> time zone, as the time would
10712+ appear with the session's <varname>TimeZone</varname> value as time zone.
10713+ </para>
10714+ <para>
10715+ <literal>timestamp with time zone '2001-02-16 20:38:40-05' at local</literal>
10716+ <returnvalue>2001-02-16 18:38:40</returnvalue>
10717+ </para></entry>
10718+ </row>
10719+
1068410720 <row>
1068510721 <entry role="func_table_entry"><para role="func_signature">
1068610722 <type>time with time zone</type> <literal>AT TIME ZONE</literal> <replaceable>zone</replaceable>
@@ -10696,6 +10732,25 @@ SELECT date_bin('15 minutes', TIMESTAMP '2020-02-11 15:44:17', TIMESTAMP '2001-0
1069610732 <returnvalue>10:34:17+00</returnvalue>
1069710733 </para></entry>
1069810734 </row>
10735+
10736+ <row>
10737+ <entry role="func_table_entry"><para role="func_signature">
10738+ <type>time with time zone</type> <literal>AT LOCAL</literal>
10739+ <returnvalue>time with time zone</returnvalue>
10740+ </para>
10741+ <para>
10742+ Converts given time <emphasis>with</emphasis> time zone to a new time
10743+ zone. Since no date is supplied, this uses the currently active UTC
10744+ offset for the session's <varname>TimeZone</varname> value.
10745+ </para>
10746+ <para>
10747+ Assuming the session's <varname>TimeZone</varname> is set to <literal>UTC</literal>:
10748+ </para>
10749+ <para>
10750+ <literal>time with time zone '05:34:17-05' at local</literal>
10751+ <returnvalue>10:34:17+00</returnvalue>
10752+ </para></entry>
10753+ </row>
1069910754 </tbody>
1070010755 </tgroup>
1070110756 </table>
@@ -10710,6 +10765,13 @@ SELECT date_bin('15 minutes', TIMESTAMP '2020-02-11 15:44:17', TIMESTAMP '2001-0
1071010765 UTC, so it is not very common in practice.
1071110766 </para>
1071210767
10768+ <para>
10769+ The syntax <literal>AT LOCAL</literal> may be used as shorthand for
10770+ <literal>AT TIME ZONE <replaceable>local</replaceable></literal>, where
10771+ <replaceable>local</replaceable> is the session's
10772+ <varname>TimeZone</varname> value.
10773+ </para>
10774+
1071310775 <para>
1071410776 Examples (assuming the current <xref linkend="guc-timezone"/> setting
1071510777 is <literal>America/Los_Angeles</literal>):
@@ -10722,14 +10784,31 @@ SELECT TIMESTAMP WITH TIME ZONE '2001-02-16 20:38:40-05' AT TIME ZONE 'America/D
1072210784
1072310785SELECT TIMESTAMP '2001-02-16 20:38:40' AT TIME ZONE 'Asia/Tokyo' AT TIME ZONE 'America/Chicago';
1072410786<lineannotation>Result: </lineannotation><computeroutput>2001-02-16 05:38:40</computeroutput>
10787+
10788+ SELECT TIMESTAMP WITH TIME ZONE '2001-02-16 20:38:40-05' AT LOCAL;
10789+ <lineannotation>Result: </lineannotation><computeroutput>2001-02-16 17:38:40</computeroutput>
10790+
10791+ SELECT TIME WITH TIME ZONE '20:38:40-05' AT LOCAL;
10792+ <lineannotation>Result: </lineannotation><computeroutput>17:38:40</computeroutput>
1072510793</screen>
1072610794 The first example adds a time zone to a value that lacks it, and
1072710795 displays the value using the current <varname>TimeZone</varname>
1072810796 setting. The second example shifts the time stamp with time zone value
1072910797 to the specified time zone, and returns the value without a time zone.
1073010798 This allows storage and display of values different from the current
1073110799 <varname>TimeZone</varname> setting. The third example converts
10732- Tokyo time to Chicago time.
10800+ Tokyo time to Chicago time. The fourth example shifts the time stamp
10801+ with time zone value to the time zone currently specified by the
10802+ <varname>TimeZone</varname> setting and returns the value without a
10803+ time zone.
10804+ </para>
10805+
10806+ <para>
10807+ The fifth example is a cautionary tale. Due to the fact that there is no
10808+ date associated with the input value, the conversion is made using the
10809+ current date of the session. Therefore, this static example may show a wrong
10810+ result depending on the time of the year it is viewed because
10811+ <literal>'America/Los_Angeles'</literal> observes Daylight Savings Time.
1073310812 </para>
1073410813
1073510814 <para>
@@ -10745,6 +10824,18 @@ SELECT TIMESTAMP '2001-02-16 20:38:40' AT TIME ZONE 'Asia/Tokyo' AT TIME ZONE 'A
1074510824 <literal><replaceable>time</replaceable> AT TIME ZONE
1074610825 <replaceable>zone</replaceable></literal>.
1074710826 </para>
10827+
10828+ <para>
10829+ The function <literal><function>timezone</function>(<replaceable>timestamp</replaceable>)</literal>
10830+ is equivalent to the SQL-conforming construct <literal><replaceable>timestamp</replaceable>
10831+ AT LOCAL</literal>.
10832+ </para>
10833+
10834+ <para>
10835+ The function <literal><function>timezone</function>(<replaceable>time</replaceable>)</literal>
10836+ is equivalent to the SQL-conforming construct <literal><replaceable>time</replaceable>
10837+ AT LOCAL</literal>.
10838+ </para>
1074810839 </sect2>
1074910840
1075010841 <sect2 id="functions-datetime-current">
0 commit comments