Bug #34512 CAST( AVG( double ) AS DECIMAL ) returns wrong results
| Submitted: | 13 Feb 2008 5:13 | Modified: | 12 Apr 2008 2:58 |
|---|---|---|---|
| Reporter: | Tak Tosh | Email Updates: | |
| Status: | Closed | Impact on me: | |
| Category: | MySQL Server: DML | Severity: | S3 (Non-critical) |
| Version: | 5.0.51a-community-nt, 5.0.54 | OS: | Any |
| Assigned to: | Alexey Kopytov | CPU Architecture: | Any |
[13 Feb 2008 5:13]
Tak Tosh
[13 Feb 2008 5:38]
Valeriy Kravchuk
Thank you for a bug report. Verified just as described: create table tt(a double) engine=MyISAM; insert into tt values (10), (20); select avg(a), cast(avg(a) as decimal) from tt;
[6 Mar 2008 15:20]
Bugs System
A patch for this bug has been committed. After review, it may be pushed to the relevant source trees for release in the next version. You can access the patch from: http://lists.mysql.com/commits/43524 ChangeSet@1.2599, 2008-03-06 18:19:47+03:00, kaa@kaamos.(none) +3 -0 Fix for bug #34512: CAST( AVG( double ) AS DECIMAL ) returns wrong results Casting AVG() to DECIMAL led to incorrect results when the arguments had a non-DECIMAL type, because in this case Item_sum_avg::val_decimal() performed the division by the number of arguments twice. Fixed by changing Item_sum_avg::val_decimal() to not rely on Item_sum_sum::val_decimal(), i.e. calculate sum and divide using DECIMAL arithmetics for DECIMAL arguments, and utilize val_real() with subsequent conversion to DECIMAL otherwise.
[28 Mar 2008 9:21]
Bugs System
Pushed into 5.1.24-rc
[28 Mar 2008 9:23]
Bugs System
Pushed into 5.0.60
[31 Mar 2008 13:58]
Bugs System
Pushed into 6.0.5-alpha
[12 Apr 2008 2:58]
Paul DuBois
Noted in 5.0.60, 5.1.24, 6.0.5 changelogs. CAST(AVG(arg) AS DECIMAL) produced incorrect results for non-DECIMAL arguments.
Portions of this website are copyright © 2001, 2002 The PHP Group
Page generated in 0.060 sec. using MySQL 8.4.7-u6-cloud
Timestamp references displayed by the system are UTC.
Content reproduced on this site is the property of the
respective copyright holders.
It is not reviewed in advance
by Oracle and does not necessarily represent the opinion of
Oracle or any other party.