Bug #9440 | Integer division results in float, no float cast. | ||
---|---|---|---|
Submitted: | 29 Mar 2005 3:09 | Modified: | 29 Mar 2005 14:56 |
Reporter: | Steven Wittens | Email Updates: | |
Status: | Won't fix | Impact on me: | |
Category: | MySQL Server | Severity: | S3 (Non-critical) |
Version: | 4.1.8 | OS: | Windows (Windows 2000) |
Assigned to: | CPU Architecture: | Any |
[29 Mar 2005 3:09]
Steven Wittens
[29 Mar 2005 9:21]
Sergei Golubchik
We cannot change the behaviour that drastically in the stable branch such as 4.1. And 5.0 already behaves according to the standard (though it's not the way you want): 1) If the declared type of both operands of a dyadic arithmetic operator is exact numeric, then the declared type of the result is an implementation-defined exact numeric type, with precision and scale determined as follows: a) Let S1 and S2 be the scale of the first and second operands respectively. b) The precision of the result of addition and subtraction is implementation-defined, and the scale is the maximum of S1 and S2. c) The precision of the result of multiplication is implementation-defined, and the scale is S1 + S2. d) The precision and scale of the result of division are implementation-defined. 2) If the declared type of either operand of a dyadic arithmetic operator is approximate numeric, then the declared type of the result is an implementation-defined approximate numeric type. Note that integer is <exact numeric type>, while MySQL double is <approximate numeric type>.
[29 Mar 2005 14:56]
Jorge del Conde
SQL:2003 says that the result of dividing "exact numerics" (decimal, numeric, integer, smallint, tinyint, bigint) must be an "exact numeric" with an "implementation-defined" precision and scale. MySQL follows that rule in 5.0.4. If I say "create table tte as select 5 / 3;" and then "show create table tte;" I see that the column is DECIMAL, not FLOAT. The complainer would prefer that the result be INTEGER, but the fact is, DECIMAL is okay.
[29 Mar 2005 18:22]
Steven Wittens
So does MySQL 5 at least support all datatypes in CAST()?