@@ -10611,7 +10611,7 @@ SELECT date_bin('15 minutes', TIMESTAMP '2020-02-11 15:44:17', TIMESTAMP '2001-0
10611
10611
</sect2>
10612
10612
10613
10613
<sect2 id="functions-datetime-zoneconvert">
10614
- <title><literal>AT TIME ZONE</literal></title>
10614
+ <title><literal>AT TIME ZONE and AT LOCAL </literal></title>
10615
10615
10616
10616
<indexterm>
10617
10617
<primary>time zone</primary>
@@ -10622,6 +10622,10 @@ SELECT date_bin('15 minutes', TIMESTAMP '2020-02-11 15:44:17', TIMESTAMP '2001-0
10622
10622
<primary>AT TIME ZONE</primary>
10623
10623
</indexterm>
10624
10624
10625
+ <indexterm>
10626
+ <primary>AT LOCAL</primary>
10627
+ </indexterm>
10628
+
10625
10629
<para>
10626
10630
The <literal>AT TIME ZONE</literal> operator converts time
10627
10631
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
10632
10636
</para>
10633
10637
10634
10638
<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>
10636
10640
<tgroup cols="1">
10637
10641
<thead>
10638
10642
<row>
@@ -10665,6 +10669,22 @@ SELECT date_bin('15 minutes', TIMESTAMP '2020-02-11 15:44:17', TIMESTAMP '2001-0
10665
10669
</para></entry>
10666
10670
</row>
10667
10671
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
+
10668
10688
<row>
10669
10689
<entry role="func_table_entry"><para role="func_signature">
10670
10690
<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
10681
10701
</para></entry>
10682
10702
</row>
10683
10703
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
+
10684
10720
<row>
10685
10721
<entry role="func_table_entry"><para role="func_signature">
10686
10722
<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
10696
10732
<returnvalue>10:34:17+00</returnvalue>
10697
10733
</para></entry>
10698
10734
</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>
10699
10754
</tbody>
10700
10755
</tgroup>
10701
10756
</table>
@@ -10710,6 +10765,13 @@ SELECT date_bin('15 minutes', TIMESTAMP '2020-02-11 15:44:17', TIMESTAMP '2001-0
10710
10765
UTC, so it is not very common in practice.
10711
10766
</para>
10712
10767
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
+
10713
10775
<para>
10714
10776
Examples (assuming the current <xref linkend="guc-timezone"/> setting
10715
10777
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
10722
10784
10723
10785
SELECT TIMESTAMP '2001-02-16 20:38:40' AT TIME ZONE 'Asia/Tokyo' AT TIME ZONE 'America/Chicago';
10724
10786
<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>
10725
10793
</screen>
10726
10794
The first example adds a time zone to a value that lacks it, and
10727
10795
displays the value using the current <varname>TimeZone</varname>
10728
10796
setting. The second example shifts the time stamp with time zone value
10729
10797
to the specified time zone, and returns the value without a time zone.
10730
10798
This allows storage and display of values different from the current
10731
10799
<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.
10733
10812
</para>
10734
10813
10735
10814
<para>
@@ -10745,6 +10824,18 @@ SELECT TIMESTAMP '2001-02-16 20:38:40' AT TIME ZONE 'Asia/Tokyo' AT TIME ZONE 'A
10745
10824
<literal><replaceable>time</replaceable> AT TIME ZONE
10746
10825
<replaceable>zone</replaceable></literal>.
10747
10826
</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>
10748
10839
</sect2>
10749
10840
10750
10841
<sect2 id="functions-datetime-current">