Skip to content

Commit ae58189

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 abb208b commit ae58189

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
@@ -7748,9 +7748,11 @@ SELECT EXTRACT(DOY FROM TIMESTAMP '2001-02-16 20:38:40');
77487748
<listitem>
77497749
<para>
77507750
For <type>timestamp with time zone</type> values, the
7751-
number of seconds since 1970-01-01 00:00:00 UTC (can be negative);
7751+
number of seconds since 1970-01-01 00:00:00 UTC (negative for
7752+
timestamps before that);
77527753
for <type>date</type> and <type>timestamp</type> values, the
7753-
number of seconds since 1970-01-01 00:00:00 local time;
7754+
nominal number of seconds since 1970-01-01 00:00:00,
7755+
without regard to timezone or daylight-savings rules;
77547756
for <type>interval</type> values, the total number
77557757
of seconds in the interval
77567758
</para>
@@ -7759,18 +7761,29 @@ SELECT EXTRACT(DOY FROM TIMESTAMP '2001-02-16 20:38:40');
77597761
SELECT EXTRACT(EPOCH FROM TIMESTAMP WITH TIME ZONE '2001-02-16 20:38:40.12-08');
77607762
<lineannotation>Result: </lineannotation><computeroutput>982384720.12</computeroutput>
77617763

7764+
SELECT EXTRACT(EPOCH FROM TIMESTAMP '2001-02-16 20:38:40.12');
7765+
<lineannotation>Result: </lineannotation><computeroutput>982355920.12</computeroutput>
7766+
77627767
SELECT EXTRACT(EPOCH FROM INTERVAL '5 days 3 hours');
77637768
<lineannotation>Result: </lineannotation><computeroutput>442800</computeroutput>
77647769
</screen>
77657770

77667771
<para>
7767-
You can convert an epoch value back to a time stamp
7772+
You can convert an epoch value back to a <type>timestamp with time zone</type>
77687773
with <function>to_timestamp</function>:
77697774
</para>
77707775
<screen>
77717776
SELECT to_timestamp(982384720.12);
77727777
<lineannotation>Result: </lineannotation><computeroutput>2001-02-17 04:38:40.12+00</computeroutput>
77737778
</screen>
7779+
7780+
<para>
7781+
Beware that applying <function>to_timestamp</function> to an epoch
7782+
extracted from a <type>date</type> or <type>timestamp</type> value
7783+
could produce a misleading result: the result will effectively
7784+
assume that the original value had been given in UTC, which might
7785+
not be the case.
7786+
</para>
77747787
</listitem>
77757788
</varlistentry>
77767789

0 commit comments

Comments
 (0)