Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1oJjSp-00030f-Py for pgsql-bugs@arkaria.postgresql.org; Thu, 04 Aug 2022 22:37:11 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1oJjSo-00049T-9b for pgsql-bugs@arkaria.postgresql.org; Thu, 04 Aug 2022 22:37:10 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1oJjSo-00049J-1Q for pgsql-bugs@lists.postgresql.org; Thu, 04 Aug 2022 22:37:10 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1oJjSh-0005r6-Dz for pgsql-bugs@lists.postgresql.org; Thu, 04 Aug 2022 22:37:09 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 274Mb1IM3675317; Thu, 4 Aug 2022 18:37:01 -0400 From: Tom Lane To: luc.lavoie@usherbrooke.ca cc: pgsql-bugs@lists.postgresql.org Subject: Re: BUG #17573: timestamptz casting precision goes down as the year goes up In-reply-to: <17573-816a53478f1c08e2@postgresql.org> References: <17573-816a53478f1c08e2@postgresql.org> Comments: In-reply-to PG Bug reporting form message dated "Thu, 04 Aug 2022 21:12:37 -0000" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <3675315.1659652621.1@sss.pgh.pa.us> Date: Thu, 04 Aug 2022 18:37:01 -0400 Message-ID: <3675316.1659652621@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk PG Bug reporting form writes: > timestamptz casting on year 2022 values returns a precision of one > microsecond (as it is expected). > As the year goes up, the precision goes down as the script below will show > for years 2022, 23621, 2713, 4022, and 8022. The issue here is not with the timestamp, nor even with the extract(). It's with your use of to_timestamp(), which takes float8, which has limited precision. The precision is disappearing in the implicit cast to float8. Prior to v14, there was also an issue with extract() returning float8, but nowadays it returns numeric. If you look directly at the extract() results you'll see no precision is lost. Maybe we should invent a variant of to_timestamp that takes numeric, but the use-case seems pretty niche ... regards, tom lane