[MDEV-5857] Truncation is not always reported when storing data into numeric fields Created: 2014-03-14  Updated: 2022-09-08

Status: Open
Project: MariaDB Server
Component/s: None
Affects Version/s: 5.3.12, 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 inserts two out-of-range numbers:

DROP TABLE IF EXISTS t1;
CREATE TABLE t1 (a TINYINT);
INSERT INTO t1 VALUES (127.1),(128);
SHOW WARNINGS;
SELECT * FROM t1;

However, only one warning is reported:

+---------+------+--------------------------------------------+
| Level   | Code | Message                                    |
+---------+------+--------------------------------------------+
| Warning | 1264 | Out of range value for column 'a' at row 2 |
+---------+------+--------------------------------------------+

A prove that both numbers were truncated:

mysql> SELECT * FROM t1;
+------+
| a    |
+------+
|  127 |
|  127 |
+------+
2 rows in set (0.00 sec)

It should be fixed to report truncation in both cases.

The problem happens because the valid range is checked after conversion to integer.
It should be checked before conversion.


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