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 1mv4kT-0005c9-Io for pgsql-bugs@arkaria.postgresql.org; Wed, 08 Dec 2021 21:45:13 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1mv4kR-0005v2-D3 for pgsql-bugs@arkaria.postgresql.org; Wed, 08 Dec 2021 21:45:11 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mv4kR-0005ut-0V for pgsql-bugs@lists.postgresql.org; Wed, 08 Dec 2021 21:45:11 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mv4kO-0000IR-Kb for pgsql-bugs@lists.postgresql.org; Wed, 08 Dec 2021 21:45: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 1B8Lj6IY3688944; Wed, 8 Dec 2021 16:45:06 -0500 From: Tom Lane To: neverov.max@gmail.com cc: pgsql-bugs@lists.postgresql.org Subject: Re: BUG #17329: Aggregate Functions Precision Error In-reply-to: <17329-8c3b204b1716bd24@postgresql.org> References: <17329-8c3b204b1716bd24@postgresql.org> Comments: In-reply-to PG Bug reporting form message dated "Wed, 08 Dec 2021 21:02:56 +0000" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <3688942.1638999906.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Wed, 08 Dec 2021 16:45:06 -0500 Message-ID: <3688943.1638999906@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: > Aggregate functions (described here > https://www.postgresql.org/docs/current/functions-aggregate.html#FUNCTIO= NS-AGGREGATE-STATISTICS-TABLE) > that are defined for double precision type suffer from loss of > significance. This is pretty much inherent in all uses of float arithmetic. You might be happier using the numeric type (of course, that's much slower). Another possibility, for some aggregates, is to order the inputs in a way that minimizes error accumulation. For example, select sum(f1 order by abs(f1)) from ... I don't know offhand what the best such incantation is for covar_pop; it might depend on the problem. regards, tom lane