Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1uOII4-000s6P-Sj for pgsql-bugs@arkaria.postgresql.org; Sun, 08 Jun 2025 15:50:32 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1uOII2-001ux3-1P for pgsql-bugs@arkaria.postgresql.org; Sun, 08 Jun 2025 15:50:30 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1uOII1-001uwu-PA for pgsql-bugs@lists.postgresql.org; Sun, 08 Jun 2025 15:50:30 +0000 Received: from sss.pgh.pa.us ([68.162.161.243]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1uOII0-000vk6-19 for pgsql-bugs@lists.postgresql.org; Sun, 08 Jun 2025 15:50:29 +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 558FoL0L183010; Sun, 8 Jun 2025 11:50:22 -0400 From: Tom Lane To: bingyanli@email.ncu.edu.cn cc: pgsql-bugs@lists.postgresql.org Subject: Re: BUG #18951: Precision loss in inner join while using SUM aggregate function In-reply-to: <18951-3092d80beab3d2ef@postgresql.org> References: <18951-3092d80beab3d2ef@postgresql.org> Comments: In-reply-to PG Bug reporting form message dated "Sun, 08 Jun 2025 14:38:55 -0000" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <183008.1749397821.1@sss.pgh.pa.us> Date: Sun, 08 Jun 2025 11:50:21 -0400 Message-ID: <183009.1749397821@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: > -- judgement: s1 = s2 + s3, However, s2 is not correctly computed [ shrug... ] If you are expecting exact results, don't use floating-point arithmetic (ie, use "numeric" not "double precision"). This example, which will result in adding values of enormously different magnitudes in various orders, is tailor-made to exhibit roundoff error. https://www.postgresql.org/docs/current/datatype-numeric.html#DATATYPE-FLOAT regards, tom lane