Re[2]: [HACKERS] Re: bug on aggregate function AVG() - Mailing list pgsql-hackers

From Sferacarta Software
Subject Re[2]: [HACKERS] Re: bug on aggregate function AVG()
Date
Msg-id 11667.981104@bo.nettuno.it
Whole thread Raw
In response to Re: [HACKERS] Re: bug on aggregate function AVG()  ("Thomas G. Lockhart" <lockhart@alumni.caltech.edu>)
List pgsql-hackers
Hi Tom,

mercoledì, 4 novembre 98, you wrote:

>> > prova=> select avg(int_2), avg(int_4), avg(int_8) from a;
>> The same on SUM():

TGL> Sure. For some reason, on most platforms integers are allowed to
TGL> overflow in Postgres. Of course, both SUM() and AVG() take a running
TGL> sum, and once they overflow you are hosed...                                        ^^^^^
I don't know what does the word "hosed" mean Tom, I hope you don't want to tell me
there's no solution for this problem.
I see that AVG() and SUM() uses an accumulator not enough big to hold
the result of calculation, but the point is: should we consider this
thing a "terrible" bug or an acceptable feature ?
What about to convert every accumulator to float8 ?

select intero4 from a;  intero4
----------
2147483647
2147483647
2147483647
(3 rows)

select sum(inter04),sum(intero4*1.0) from a;      sum|       sum
----------+----------
2147483645|6442450941
(1 row)

select avg(intero4),avg(intero4*1.0) from a;     avg|       avg
---------+----------
715827881|2147483647
(1 row)

Anyway I think we need to work a little bit on aggregates:

MIN() and MAX() doesn't accept a string as parameter.
SUM() and AVG() gives a wrong result because it goes on overflow.
and none of them allows the clause DISTINCT.

What do you think about ? ;)
      Jose'




pgsql-hackers by date:

Previous
From: A James Lewis
Date:
Subject: Re: [HACKERS] Warning!!
Next
From: Tom Lane
Date:
Subject: Re: [HACKERS] Mixing library versions