Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1ib4YY-0003QU-5I for pgsql-bugs@arkaria.postgresql.org; Sat, 30 Nov 2019 15:21:10 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1ib4YW-0003sK-VT for pgsql-bugs@arkaria.postgresql.org; Sat, 30 Nov 2019 15:21:08 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1ib4YW-0003ob-If for pgsql-bugs@lists.postgresql.org; Sat, 30 Nov 2019 15:21:08 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1ib4YS-0006Ar-TY for pgsql-bugs@postgresql.org; Sat, 30 Nov 2019 15:21:07 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id xAUFL1hG017992; Sat, 30 Nov 2019 10:21:01 -0500 From: Tom Lane To: Petr Fedorov cc: pgsql-bugs@postgresql.org Subject: Re: Since '2001-09-09 01:46:40'::timestamp microseconds are lost when extracting epoch In-reply-to: <42b73d2d-da12-ba9f-570a-420e0cce19d9@phystech.edu> References: <42b73d2d-da12-ba9f-570a-420e0cce19d9@phystech.edu> Comments: In-reply-to Petr Fedorov message dated "Sat, 30 Nov 2019 12:28:18 +0300" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <17990.1575127261.1@sss.pgh.pa.us> Date: Sat, 30 Nov 2019 10:21:01 -0500 Message-ID: <17991.1575127261@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Petr Fedorov writes: > select extract(epoch from '2001-09-09 01:46:40.000021'::timestamp) > returns 1000000000.00002 - 1 microsecond is truncated. > Obviously, it is due to the fact that extract epoch returns double > precision which in turn has 15 decimal digits precision. I can't get very excited about this. However, it might be worth noting that v12 and HEAD print "1000000000.000021" as expected, thanks to the Ryu float output code. You can get that from older branches as well if you set extra_float_digits = 1. By my arithmetic, IEEE float8 ought to be able to represent microseconds accurately out to about 285 years either way from the 1970 epoch, so for practical purposes it'll be fine for a long time. regards, tom lane