[MDEV-5888] Inconsistency between implicit and explicit conversion of 1/3 to char Created: 2014-03-17  Updated: 2022-09-08

Status: Open
Project: MariaDB Server
Component/s: None
Affects Version/s: 5.5.36, 10.0.9
Fix Version/s: 5.5

Type: Bug Priority: Minor
Reporter: Alexander Barkov Assignee: Alexander Barkov
Resolution: Unresolved Votes: 0
Labels: 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.


Generated at Thu Feb 08 07:07:48 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.