Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 5706c48

Browse files
committed
Doc: improve explanation of EXTRACT(EPOCH) for timestamp without tz.
Try to be clearer about what computation is actually happening here. Per bug #16797 from Dana Burd. Discussion: https://postgr.es/m/16797-f264b0b980b53b8b@postgresql.org
1 parent 5f95664 commit 5706c48

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

doc/src/sgml/func.sgml

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8107,9 +8107,11 @@ SELECT EXTRACT(DOY FROM TIMESTAMP '2001-02-16 20:38:40');
81078107
<listitem>
81088108
<para>
81098109
For <type>timestamp with time zone</type> values, the
8110-
number of seconds since 1970-01-01 00:00:00 UTC (can be negative);
8110+
number of seconds since 1970-01-01 00:00:00 UTC (negative for
8111+
timestamps before that);
81118112
for <type>date</type> and <type>timestamp</type> values, the
8112-
number of seconds since 1970-01-01 00:00:00 local time;
8113+
nominal number of seconds since 1970-01-01 00:00:00,
8114+
without regard to timezone or daylight-savings rules;
81138115
for <type>interval</type> values, the total number
81148116
of seconds in the interval
81158117
</para>
@@ -8118,18 +8120,29 @@ SELECT EXTRACT(DOY FROM TIMESTAMP '2001-02-16 20:38:40');
81188120
SELECT EXTRACT(EPOCH FROM TIMESTAMP WITH TIME ZONE '2001-02-16 20:38:40.12-08');
81198121
<lineannotation>Result: </lineannotation><computeroutput>982384720.12</computeroutput>
81208122

8123+
SELECT EXTRACT(EPOCH FROM TIMESTAMP '2001-02-16 20:38:40.12');
8124+
<lineannotation>Result: </lineannotation><computeroutput>982355920.12</computeroutput>
8125+
81218126
SELECT EXTRACT(EPOCH FROM INTERVAL '5 days 3 hours');
81228127
<lineannotation>Result: </lineannotation><computeroutput>442800</computeroutput>
81238128
</screen>
81248129

81258130
<para>
8126-
You can convert an epoch value back to a time stamp
8131+
You can convert an epoch value back to a <type>timestamp with time zone</type>
81278132
with <function>to_timestamp</function>:
81288133
</para>
81298134
<screen>
81308135
SELECT to_timestamp(982384720.12);
81318136
<lineannotation>Result: </lineannotation><computeroutput>2001-02-17 04:38:40.12+00</computeroutput>
81328137
</screen>
8138+
8139+
<para>
8140+
Beware that applying <function>to_timestamp</function> to an epoch
8141+
extracted from a <type>date</type> or <type>timestamp</type> value
8142+
could produce a misleading result: the result will effectively
8143+
assume that the original value had been given in UTC, which might
8144+
not be the case.
8145+
</para>
81338146
</listitem>
81348147
</varlistentry>
81358148

0 commit comments

Comments
 (0)