Bug #4388 Aggregate Functions Return Wrong Column Type
Submitted: 2 Jul 2004 22:25 Modified: 26 Jul 2005 17:48
Reporter: Marcel Fernandes Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server Severity:S3 (Non-critical)
Version:4.0.18-nt OS:Microsoft Windows (Windows XP SP1)
Assigned to: Alexey Botchkov CPU Architecture:Any

[2 Jul 2004 22:25] Marcel Fernandes
Description:
When I use SUM() ,for exemple, in an int column, I guess that the column result type should be int and not double.
A sum of int values is always an int value.
Am I right?

How to repeat:
CREATE TABLE tbtemp TYPE=HEAP MAX_ROWS=1
SELECT SUM(int column), SUM(float column) FROM any table;
DESCRIBE tbtemp
[14 Jul 2004 18:15] Hartmut Holzgraefe
SQL functions can set the precision (length, number of decimal digits) of their result but are bound to a single result type.

So SUM() will always return a DOUBLE result, if all input values are INT
this will be a DOUBLE with zero decimals though.
[14 Jul 2004 19:22] Sergei Golubchik
No, e.g. MIN() returns the result that has the type of its argument.
Bug confirmed
[4 Sep 2004 8:27] Sergei Glukhov
ChangeSet
  1.2004 04/09/04
  Fix for bug #4388: Aggregate Functions Return Wrong Column Type
[24 Sep 2004 12:40] Alexey Botchkov
Presently SUM function uses float-point arithmetic internally, and this won't be changed unthil we implement precise maths (should be 5.1)
[26 Jul 2005 17:48] Peter Gulutzan
Due to changes in the way we handle DECIMALs, the example aggregation
works in MySQL 5.0.