Details
-
Bug
-
Status: Open (View Workflow)
-
Minor
-
Resolution: Unresolved
-
5.5.36, 10.0.9
-
None
-
None
Description
This SQL script:
DROP TABLE IF EXISTS t1;
|
CREATE TABLE t1 (a CHAR(10));
|
INSERT INTO t1 VALUES (1/3);
|
SHOW WARNINGS;
|
SELECT *, CAST(1/3 AS CHAR) FROM t1;
|
demonstrates some inconsistency between
implicit and explicit conversion of 1/3 to CHAR:
+---------+------+----------------------------------------+
|
| Level | Code | Message |
|
+---------+------+----------------------------------------+
|
| Warning | 1265 | Data truncated for column 'a' at row 1 |
|
+---------+------+----------------------------------------+
|
1 row in set (0.00 sec)
|
 |
+------------+-------------------+
|
| a | CAST(1/3 AS CHAR) |
|
+------------+-------------------+
|
| 0.33333333 | 0.3333 |
|
+------------+-------------------+
|
1 row in set (0.00 sec)
|
Notice, explicit CAST preserves only 4 fractional digits, while
implicit CAST preserves all fractional digits.
The correct behaviour is probably to preserve all digits.