Re: [HACKERS] 6.5.0 - Overflow bug in AVG( ) - Mailing list pgsql-hackers

From Tom Lane
Subject Re: [HACKERS] 6.5.0 - Overflow bug in AVG( )
Date
Msg-id 24898.929543873@sss.pgh.pa.us
Whole thread Raw
In response to 6.5.0 - Overflow bug in AVG( )  ("Gene Sokolov" <hook@aktrad.ru>)
List pgsql-hackers
"Gene Sokolov" <hook@aktrad.ru> writes:
> test1=>  select count(*), max("ID"), min("ID"), avg("ID") from "ItemsBars";
>  count|    max|  min| avg
> ------+-------+-----+----
> 677719|3075717|61854|-251

> Overflow, perhaps?

sum() and avg() for int fields use int accumulators.  You might want
to use avg(float8(field)) to get a less-likely-to-overflow result.

Someday it'd be a good idea to revise the sum() and avg() aggregates
to use float or numeric accumulators in all cases.  This'd require
inventing a few more cross-data-type operators...
        regards, tom lane


pgsql-hackers by date:

Previous
From: Thomas Lockhart
Date:
Subject: Re: [HACKERS] decimal & numeric report bug
Next
From: Tom Lane
Date:
Subject: Re: [HACKERS] 6.5.0 - Overflow bug in AVG( )