Re: BUG #17329: Aggregate Functions Precision Error - Mailing list pgsql-bugs

From Tom Lane
Subject Re: BUG #17329: Aggregate Functions Precision Error
Date
Msg-id 3688943.1638999906@sss.pgh.pa.us
Whole thread Raw
In response to BUG #17329: Aggregate Functions Precision Error  (PG Bug reporting form <noreply@postgresql.org>)
List pgsql-bugs
PG Bug reporting form <noreply@postgresql.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



pgsql-bugs by date:

Previous
From: PG Bug reporting form
Date:
Subject: BUG #17329: Aggregate Functions Precision Error
Next
From: "James Pang (chaolpan)"
Date:
Subject: RE: BUG #17326: Postgres crashed when pg_reload_conf() with ssl certificate parameters