[MDEV-29041] Redundant truncation warning on CAST(string_column AS DECIMAL) Created: 2022-07-06  Updated: 2022-07-06  Resolved: 2022-07-06

Status: Closed
Project: MariaDB Server
Component/s: Data types
Affects Version/s: 10.3, 10.4, 10.5, 10.6, 10.7, 10.8, 10.9
Fix Version/s: 10.3.36, 10.4.26, 10.5.17, 10.6.9, 10.7.5, 10.8.4, 10.9.2

Type: Bug Priority: Critical
Reporter: Alexander Barkov Assignee: Alexander Barkov
Resolution: Fixed Votes: 0
Labels: None

Issue Links:
Blocks
blocks MDEV-21445 Strange/inconsistent behavior of IN c... Closed

 Description   

CREATE OR REPLACE TABLE t1 (a CHAR(10));
INSERT INTO t1 VALUES ('x');
SELECT CAST(a AS DECIMAL(10,2)) FROM t1;
SHOW WARNINGS;

+---------+------+---------------------------------------------------------+
| Level   | Code | Message                                                 |
+---------+------+---------------------------------------------------------+
| Warning | 1918 | Encountered illegal value '' when converting to DECIMAL |
| Warning | 1292 | Truncated incorrect DECIMAL value: 'x         '         |
+---------+------+---------------------------------------------------------+

Notice two warnings. Just one truncation wanrning should be enough, the second one.

The same problem is repeatable with VARCHAR:

CREATE OR REPLACE TABLE t1 (a VARCHAR(10));
INSERT INTO t1 VALUES ('x');
SELECT CAST(a AS DECIMAL(10,2)) FROM t1;
SHOW WARNINGS;

+---------+------+---------------------------------------------------------+
| Level   | Code | Message                                                 |
+---------+------+---------------------------------------------------------+
| Warning | 1918 | Encountered illegal value '' when converting to DECIMAL |
| Warning | 1292 | Truncated incorrect DECIMAL value: 'x'                  |
+---------+------+---------------------------------------------------------+

The same problem is repeatable with TEXT:

CREATE OR REPLACE TABLE t1 (a TEXT);
INSERT INTO t1 VALUES ('x');
SELECT CAST(a AS DECIMAL(10,2)) FROM t1;
SHOW WARNINGS;

+---------+------+---------------------------------------------------------+
| Level   | Code | Message                                                 |
+---------+------+---------------------------------------------------------+
| Warning | 1918 | Encountered illegal value '' when converting to DECIMAL |
| Warning | 1292 | Truncated incorrect DECIMAL value: 'x'                  |
+---------+------+---------------------------------------------------------+

CAST to other numeric data types works fine

CAST(AS DOUBLE) correctly returns one warning:

CREATE OR REPLACE TABLE t1 (a CHAR(10));
INSERT INTO t1 VALUES ('x');
SELECT CAST(a AS DOUBLE) FROM t1;
SHOW WARNINGS;

+---------+------+------------------------------------------------+
| Level   | Code | Message                                        |
+---------+------+------------------------------------------------+
| Warning | 1292 | Truncated incorrect DOUBLE value: 'x         ' |
+---------+------+------------------------------------------------+

CAST(AS INT) also correctly returns one warning:

CREATE OR REPLACE TABLE t1 (a CHAR(10));
INSERT INTO t1 VALUES ('x');
SELECT CAST(a AS INT) FROM t1;
SHOW WARNINGS;

+---------+------+----------------------------------------+
| Level   | Code | Message                                |
+---------+------+----------------------------------------+
| Warning | 1292 | Truncated incorrect INTEGER value: 'x' |
+---------+------+----------------------------------------+



 Comments   
Comment by Alexander Barkov [ 2022-07-06 ]

Changing status to Critical as it block a critical issue MDEV-21445.

Generated at Thu Feb 08 10:05:25 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.