pg.ddx.io pgsql-bugs@postgresql.org mailing list archive
help / color / mirror / Atom feedRounding error on extract(epoch ..)
3+ messages / 2 participants
[nested] [flat]
* Rounding error on extract(epoch ..)
@ 2014-01-24 16:40 Moshe Jacobson <moshe@neadwerx.com>
2014-01-24 16:52 ` Re: Rounding error on extract(epoch ..) Tom Lane <tgl@sss.pgh.pa.us>
0 siblings, 1 reply; 3+ messages in thread
From: Moshe Jacobson @ 2014-01-24 16:40 UTC (permalink / raw)
To: pgsql-bugs
It seems that extract(epoch ..) does not preserve the entire precision of
the passed-in timestamp. In the following example, it rounds to the nearest
0.00001:
> select extract(epoch from '2014-01-21 16:10:30.403777'::timestamp);
date_part
------------------
1390320630.40378
(1 row)
Just to be sure, I convert this value back to timestamp and it is still
rounded (and incorrect):
> select to_timestamp(1390320630.40378);
to_timestamp
------------------------------
2014-01-21 11:10:30.40378-05
(1 row)
Oddly, when the result of extract(epoch) is passed directly back into
to_timestamp, the result is correct!
> select to_timestamp(extract(epoch from '2014-01-21 16:10:30.403777'::timestamp));
to_timestamp
-------------------------------
2014-01-21 11:10:30.403777-05
(1 row)
Moshe Jacobson
Manager of Systems Engineering, Nead Werx Inc. <http://www.neadwerx.com;
2323 Cumberland Parkway · Suite 201 · Atlanta, GA 30339
“Quality is not an act, it is a habit.” — Aristotle
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: Rounding error on extract(epoch ..)
2014-01-24 16:40 Rounding error on extract(epoch ..) Moshe Jacobson <moshe@neadwerx.com>
@ 2014-01-24 16:52 ` Tom Lane <tgl@sss.pgh.pa.us>
2014-01-24 17:56 ` Re: Rounding error on extract(epoch ..) Moshe Jacobson <moshe@neadwerx.com>
0 siblings, 1 reply; 3+ messages in thread
From: Tom Lane @ 2014-01-24 16:52 UTC (permalink / raw)
To: Moshe Jacobson <moshe@neadwerx.com>; +Cc: pgsql-bugs
Moshe Jacobson <moshe@neadwerx.com> writes:
> It seems that extract(epoch ..) does not preserve the entire precision of
> the passed-in timestamp.
The result is float8, so being good to about 16 digits is expected
behavior.
regards, tom lane
--
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: Rounding error on extract(epoch ..)
2014-01-24 16:40 Rounding error on extract(epoch ..) Moshe Jacobson <moshe@neadwerx.com>
2014-01-24 16:52 ` Re: Rounding error on extract(epoch ..) Tom Lane <tgl@sss.pgh.pa.us>
@ 2014-01-24 17:56 ` Moshe Jacobson <moshe@neadwerx.com>
0 siblings, 0 replies; 3+ messages in thread
From: Moshe Jacobson @ 2014-01-24 17:56 UTC (permalink / raw)
To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: pgsql-bugs
On Jan 24, 2014 11:52 AM, "Tom Lane" <tgl@sss.pgh.pa.us> wrote:
> The result is float8, so being good to about 16 digits is expected
> behavior.
I see. But how is it that the correct result is returned when I pass the
output of extract straight into to_timestamp?
^ permalink raw reply [nested|flat] 3+ messages in thread
end of thread, other threads:[~2014-01-24 17:56 UTC | newest]
Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2014-01-24 16:40 Rounding error on extract(epoch ..) Moshe Jacobson <moshe@neadwerx.com>
2014-01-24 16:52 ` Tom Lane <tgl@sss.pgh.pa.us>
2014-01-24 17:56 ` Moshe Jacobson <moshe@neadwerx.com>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox