Skip to content

Commit 1cfdeda

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 d56ea24 commit 1cfdeda

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

doc/src/sgml/func.sgml

+17-4
Original file line numberDiff line numberDiff line change
@@ -7555,9 +7555,11 @@ SELECT EXTRACT(DOY FROM TIMESTAMP '2001-02-16 20:38:40');
75557555
<listitem>
75567556
<para>
75577557
For <type>timestamp with time zone</type> values, the
7558-
number of seconds since 1970-01-01 00:00:00 UTC (can be negative);
7558+
number of seconds since 1970-01-01 00:00:00 UTC (negative for
7559+
timestamps before that);
75597560
for <type>date</type> and <type>timestamp</type> values, the
7560-
number of seconds since 1970-01-01 00:00:00 local time;
7561+
nominal number of seconds since 1970-01-01 00:00:00,
7562+
without regard to timezone or daylight-savings rules;
75617563
for <type>interval</type> values, the total number
75627564
of seconds in the interval
75637565
</para>
@@ -7566,18 +7568,29 @@ SELECT EXTRACT(DOY FROM TIMESTAMP '2001-02-16 20:38:40');
75667568
SELECT EXTRACT(EPOCH FROM TIMESTAMP WITH TIME ZONE '2001-02-16 20:38:40.12-08');
75677569
<lineannotation>Result: </lineannotation><computeroutput>982384720.12</computeroutput>
75687570

7571+
SELECT EXTRACT(EPOCH FROM TIMESTAMP '2001-02-16 20:38:40.12');
7572+
<lineannotation>Result: </lineannotation><computeroutput>982355920.12</computeroutput>
7573+
75697574
SELECT EXTRACT(EPOCH FROM INTERVAL '5 days 3 hours');
75707575
<lineannotation>Result: </lineannotation><computeroutput>442800</computeroutput>
75717576
</screen>
75727577

75737578
<para>
7574-
You can convert an epoch value back to a time stamp
7575-
with <function>to_timestamp</>:
7579+
You can convert an epoch value back to a <type>timestamp with time zone</type>
7580+
with <function>to_timestamp</function>:
75767581
</para>
75777582
<screen>
75787583
SELECT to_timestamp(982384720.12);
75797584
<lineannotation>Result: </lineannotation><computeroutput>2001-02-17 04:38:40.12+00</computeroutput>
75807585
</screen>
7586+
7587+
<para>
7588+
Beware that applying <function>to_timestamp</function> to an epoch
7589+
extracted from a <type>date</type> or <type>timestamp</type> value
7590+
could produce a misleading result: the result will effectively
7591+
assume that the original value had been given in UTC, which might
7592+
not be the case.
7593+
</para>
75817594
</listitem>
75827595
</varlistentry>
75837596

0 commit comments

Comments
 (0)