agora inbox for pgsql-bugs@postgresql.org
help / color / mirror / Atom feedFrom: PG Bug reporting form <noreply@postgresql.org>
To: pgsql-bugs@lists.postgresql.org
Cc: theshallow27@gmail.com
Subject: BUG #19741: `avg(double precision)` overflows on cancelling finite inputs whose mean is representable
Date: Fri, 02 Oct 2026 22:38:39 +0000
Message-ID: <19741-01386c4f17e36788@postgresql.org> (raw)
The following bug has been logged on the website:
Bug reference: 19741
Logged by: Shallow
Email address: theshallow27@gmail.com
PostgreSQL version: 18.6
Operating system: Linux
Description:
The arithmetic mean of two finite values, `1e154` and `-1e154`, is exactly
zero. PostgreSQL's `avg(double precision)` raises an overflow instead. The
same input's sum is zero and its numeric average is zero. The aggregate's
shared float8 accumulation state appears to overflow while accumulating
values used for variance, although `avg` needs only the count and sum for
its
final result.
**Reproduction:**
```sql
SELECT avg(x)
FROM unnest(ARRAY[1e154, -1e154]::double precision[]) AS t(x);
```
**Actual result:** SQLSTATE `22003`, `value out of range: overflow`.
Reference calculation:
```sql
SELECT sum(x), avg(x::numeric)
FROM unnest(ARRAY[1e154, -1e154]::double precision[]) AS t(x);
-- 0 | 0
```
**Expected result:** `avg(double precision)` should return `0` for these
finite
inputs rather than failing due to an intermediate value that does not
contribute to the arithmetic mean.
view thread (2+ messages) latest in thread
Message-ID: <19741-01386c4f17e36788@postgresql.org>
Permalink: ../19741-01386c4f17e36788@postgresql.org/
Also on: postgresql.org/message-id/19741-01386c4f17e36788@postgresql.org
reply
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-bugs@postgresql.org
Cc: noreply@postgresql.org, pgsql-bugs@lists.postgresql.org, theshallow27@gmail.com
Subject: Re: BUG #19741: `avg(double precision)` overflows on cancelling finite inputs whose mean is representable
In-Reply-To: <19741-01386c4f17e36788@postgresql.org>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox