Re: BUG #17329: Aggregate Functions Precision Error

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: neverov(dot)max(at)gmail(dot)com
Cc: pgsql-bugs(at)lists(dot)postgresql(dot)org
Subject: Re: BUG #17329: Aggregate Functions Precision Error
Date: 2021-12-08 21:45:06
Message-ID: 3688943.1638999906@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

PG Bug reporting form <noreply(at)postgresql(dot)org> writes:
> Aggregate functions (described here
> https://www.postgresql.org/docs/current/functions-aggregate.html#FUNCTIONS-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

In response to

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message James Pang (chaolpan) 2021-12-09 03:34:02 RE: BUG #17326: Postgres crashed when pg_reload_conf() with ssl certificate parameters
Previous Message PG Bug reporting form 2021-12-08 21:02:56 BUG #17329: Aggregate Functions Precision Error