Skip to content

Commit 4a4cad9

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 7fe23c8 commit 4a4cad9

File tree

1 file changed

+17
-7
lines changed

1 file changed

+17
-7
lines changed

doc/src/sgml/func.sgml

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7298,9 +7298,11 @@ SELECT EXTRACT(DOY FROM TIMESTAMP '2001-02-16 20:38:40');
72987298
<listitem>
72997299
<para>
73007300
For <type>timestamp with time zone</type> values, the
7301-
number of seconds since 1970-01-01 00:00:00 UTC (can be negative);
7301+
number of seconds since 1970-01-01 00:00:00 UTC (negative for
7302+
timestamps before that);
73027303
for <type>date</type> and <type>timestamp</type> values, the
7303-
number of seconds since 1970-01-01 00:00:00 local time;
7304+
nominal number of seconds since 1970-01-01 00:00:00,
7305+
without regard to timezone or daylight-savings rules;
73047306
for <type>interval</type> values, the total number
73057307
of seconds in the interval
73067308
</para>
@@ -7309,20 +7311,28 @@ SELECT EXTRACT(DOY FROM TIMESTAMP '2001-02-16 20:38:40');
73097311
SELECT EXTRACT(EPOCH FROM TIMESTAMP WITH TIME ZONE '2001-02-16 20:38:40.12-08');
73107312
<lineannotation>Result: </lineannotation><computeroutput>982384720.12</computeroutput>
73117313

7314+
SELECT EXTRACT(EPOCH FROM TIMESTAMP '2001-02-16 20:38:40.12');
7315+
<lineannotation>Result: </lineannotation><computeroutput>982355920.12</computeroutput>
7316+
73127317
SELECT EXTRACT(EPOCH FROM INTERVAL '5 days 3 hours');
73137318
<lineannotation>Result: </lineannotation><computeroutput>442800</computeroutput>
73147319
</screen>
73157320

73167321
<para>
7317-
Here is how you can convert an epoch value back to a time
7318-
stamp:
7322+
You can convert an epoch value back to a <type>timestamp with time zone</type>
7323+
with <function>to_timestamp</function>:
73197324
</para>
73207325
<screen>
7321-
SELECT TIMESTAMP WITH TIME ZONE 'epoch' + 982384720.12 * INTERVAL '1 second';
7326+
SELECT to_timestamp(982384720.12);
7327+
<lineannotation>Result: </lineannotation><computeroutput>2001-02-17 04:38:40.12+00</computeroutput>
73227328
</screen>
7329+
73237330
<para>
7324-
(The <function>to_timestamp</> function encapsulates the above
7325-
conversion.)
7331+
Beware that applying <function>to_timestamp</function> to an epoch
7332+
extracted from a <type>date</type> or <type>timestamp</type> value
7333+
could produce a misleading result: the result will effectively
7334+
assume that the original value had been given in UTC, which might
7335+
not be the case.
73267336
</para>
73277337
</listitem>
73287338
</varlistentry>

0 commit comments

Comments
 (0)