[MDEV-8515] Explicit and implicit CAST from string to integer work differently Created: 2015-07-21  Updated: 2019-11-18

Status: Open
Project: MariaDB Server
Component/s: Data types
Affects Version/s: 5.5, 10.0, 10.1, 10.2, 10.3, 10.4
Fix Version/s: 10.4

Type: Bug Priority: Major
Reporter: Alexander Barkov Assignee: Alexander Barkov
Resolution: Unresolved Votes: 0
Labels: None

Issue Links:
Relates
relates to MDEV-8514 Storing '1e-1000000000000' into an IN... Open
Epic Link: Data type cleanups

 Description   

Implicit cast:

DROP TABLE IF EXISTS t1;
CREATE TABLE t1 (a INT);
INSERT INTO t1 VALUES ('1.5'),('1e2');
SELECT * FROM t1;

returns:

+------+
| a    |
+------+
|    2 |
|  100 |
+------+

I.e. it understands floating point formats.

Explicit CAST works differently:

SELECT CAST('1.5' AS SIGNED), CAST('1e2' AS SIGNED);
SHOW WARNINGS;

returns:

+-----------------------+-----------------------+
| CAST('1.5' AS SIGNED) | CAST('1e2' AS SIGNED) |
+-----------------------+-----------------------+
|                     1 |                     1 |
+-----------------------+-----------------------+
1 row in set, 2 warnings (0.00 sec)
 
+---------+------+------------------------------------------+
| Level   | Code | Message                                  |
+---------+------+------------------------------------------+
| Warning | 1292 | Truncated incorrect INTEGER value: '1.5' |
| Warning | 1292 | Truncated incorrect INTEGER value: '1e2' |
+---------+------+------------------------------------------+

i.e. it does not understand floating point formats.

Explicit CAST should be fixed to understand floating point format.


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