Bug #4388 Aggregate Functions Return Wrong Column Type
Submitted: 3 Jul 2004 0:25 Modified: 26 Jul 2005 19:48
Reporter: Marcel Fernandes
Status: Closed
Category:Server Severity:S3 (Non-critical)
Version:4.0.18-nt OS:Microsoft Windows (Windows XP SP1)
Assigned to: Alexey Botchkov Target Version:

[3 Jul 2004 0: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 20: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 21:22] Sergei Golubchik
No, e.g. MIN() returns the result that has the type of its argument.
Bug confirmed
[4 Sep 2004 10:27] Sergey Gluhov
ChangeSet
  1.2004 04/09/04
  Fix for bug #4388: Aggregate Functions Return Wrong Column Type
[24 Sep 2004 14: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 19:48] Peter Gulutzan
Due to changes in the way we handle DECIMALs, the example aggregation
works in MySQL 5.0.