[MDEV-5809] Conversion from string to number is inconsistent Created: 2014-03-10  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 INT);
INSERT INTO t1 VALUES ('10.6');
SELECT a, CAST('10.6' AS SIGNED) FROM t1;
SHOW WARNINGS;

returns:

+------+------------------------+
| a    | CAST('10.6' AS SIGNED) |
+------+------------------------+
|   11 |                     10 |
+------+------------------------+
1 row in set, 1 warning (0.00 sec)
+---------+------+-------------------------------------------+
| Level   | Code | Message                                   |
+---------+------+-------------------------------------------+
| Warning | 1292 | Truncated incorrect INTEGER value: '10.6' |
+---------+------+-------------------------------------------+
1 row in set (0.00 sec)

Notice, when converting to a field, it rounds silently.
When converting in CAST, it truncates with a warning.

It should be fixed to expose similar behaviour in both cases.

The questions is: which of them is correct?


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