Re: [HACKERS] 6.5.0 - Overflow bug in AVG( )

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "Gene Sokolov" <hook(at)aktrad(dot)ru>
Cc: pgsql-hackers(at)postgreSQL(dot)org
Subject: Re: [HACKERS] 6.5.0 - Overflow bug in AVG( )
Date: 1999-06-16 14:37:53
Message-ID: 24898.929543873@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

"Gene Sokolov" <hook(at)aktrad(dot)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

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 1999-06-16 14:52:12 Re: [HACKERS] 6.5.0 - Overflow bug in AVG( )
Previous Message Thomas Lockhart 1999-06-16 14:25:16 Re: [HACKERS] decimal & numeric report bug