Skip to content

Commit 4d3f03f

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 32d6287 commit 4d3f03f

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
@@ -9354,9 +9354,11 @@ SELECT EXTRACT(DOY FROM TIMESTAMP '2001-02-16 20:38:40');
93549354
<listitem>
93559355
<para>
93569356
For <type>timestamp with time zone</type> values, the
9357-
number of seconds since 1970-01-01 00:00:00 UTC (can be negative);
9357+
number of seconds since 1970-01-01 00:00:00 UTC (negative for
9358+
timestamps before that);
93589359
for <type>date</type> and <type>timestamp</type> values, the
9359-
number of seconds since 1970-01-01 00:00:00 local time;
9360+
nominal number of seconds since 1970-01-01 00:00:00,
9361+
without regard to timezone or daylight-savings rules;
93609362
for <type>interval</type> values, the total number
93619363
of seconds in the interval
93629364
</para>
@@ -9365,18 +9367,29 @@ SELECT EXTRACT(DOY FROM TIMESTAMP '2001-02-16 20:38:40');
93659367
SELECT EXTRACT(EPOCH FROM TIMESTAMP WITH TIME ZONE '2001-02-16 20:38:40.12-08');
93669368
<lineannotation>Result: </lineannotation><computeroutput>982384720.12</computeroutput>
93679369

9370+
SELECT EXTRACT(EPOCH FROM TIMESTAMP '2001-02-16 20:38:40.12');
9371+
<lineannotation>Result: </lineannotation><computeroutput>982355920.12</computeroutput>
9372+
93689373
SELECT EXTRACT(EPOCH FROM INTERVAL '5 days 3 hours');
93699374
<lineannotation>Result: </lineannotation><computeroutput>442800</computeroutput>
93709375
</screen>
93719376

93729377
<para>
9373-
You can convert an epoch value back to a time stamp
9378+
You can convert an epoch value back to a <type>timestamp with time zone</type>
93749379
with <function>to_timestamp</function>:
93759380
</para>
93769381
<screen>
93779382
SELECT to_timestamp(982384720.12);
93789383
<lineannotation>Result: </lineannotation><computeroutput>2001-02-17 04:38:40.12+00</computeroutput>
93799384
</screen>
9385+
9386+
<para>
9387+
Beware that applying <function>to_timestamp</function> to an epoch
9388+
extracted from a <type>date</type> or <type>timestamp</type> value
9389+
could produce a misleading result: the result will effectively
9390+
assume that the original value had been given in UTC, which might
9391+
not be the case.
9392+
</para>
93809393
</listitem>
93819394
</varlistentry>
93829395

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy