Bug #115270 Inconsistent type conversions in update and select statements
Submitted: 10 Jun 13:06 Modified: 10 Jun 13:39
Reporter: Huicong Xu Email Updates:
Status: Not a Bug Impact on me:
None 
Category:MySQL Server Severity:S3 (Non-critical)
Version:8.0.36 OS:Ubuntu (22.04)
Assigned to: CPU Architecture:Any
Tags: type conversions

[10 Jun 13:06] Huicong Xu
Description:
Hi.
In my tests, I found inconsistencies between select statements and update statements for the same expression.It works in select statements, but reports error in update statements. I think this creates an illusion for users, which can lead to other errors.
Here is my test case.It is wrong in MySQL, but correct in Mariadb.
In MySQL
--- ini ---
CREATE TABLE t0(c0 TEXT , c1 DECIMAL , c2 BLOB );
INSERT INTO t0 VALUES ('zeGTVmzYyL', -10723, 'zeGTVmzYyL');
INSERT INTO t0(c2, c1, c0) VALUES ('m6MkaimUzq', -10811, 'm6MkaimUzq');
INSERT IGNORE  INTO t0(c0) VALUES ('u3pHrhF5LF');

mysql> SELECT * FROM t0 WHERE ((435600036)>=('-'));
+------------+--------+------------+
| c0         | c1     | c2         |
+------------+--------+------------+
| zeGTVmzYyL | -10723 | zeGTVmzYyL |
| m6MkaimUzq | -10811 | m6MkaimUzq |
| u3pHrhF5LF |   NULL | NULL       |
+------------+--------+------------+
3 rows in set, 1 warning (0.00 sec)

mysql> UPDATE t0 SET c0='e9pvumJh2h', c1=3268, c2='e9pvumJh2h' WHERE ((435600036)>=('-'));
ERROR 1292 (22007): Truncated incorrect DOUBLE value: '-'

In Mariadb
mysql> SELECT * FROM t0 WHERE ((435600036)>=('-'));
+------------+--------+------------+
| c0         | c1     | c2         |
+------------+--------+------------+
| zeGTVmzYyL | -10723 | zeGTVmzYyL |
| m6MkaimUzq | -10811 | m6MkaimUzq |
| u3pHrhF5LF |   NULL | NULL       |
+------------+--------+------------+
3 rows in set, 1 warning (0.00 sec)

mysql> UPDATE t0 SET c0='e9pvumJh2h', c1=3268, c2='e9pvumJh2h' WHERE ((435600036)>=('-'));
Query OK, 3 rows affected, 1 warning (0.00 sec)
Rows matched: 3  Changed: 3  Warnings: 1

mysql> SELECT * FROM t0 WHERE ((435600036)>=('-'));
+------------+------+------------+
| c0         | c1   | c2         |
+------------+------+------------+
| e9pvumJh2h | 3268 | e9pvumJh2h |
| e9pvumJh2h | 3268 | e9pvumJh2h |
| e9pvumJh2h | 3268 | e9pvumJh2h |
+------------+------+------------+
3 rows in set, 1 warning (0.00 sec)

Thank for your reply.

How to repeat:
--- ini ---
CREATE TABLE t0(c0 TEXT , c1 DECIMAL , c2 BLOB );
INSERT INTO t0 VALUES ('zeGTVmzYyL', -10723, 'zeGTVmzYyL');
INSERT INTO t0(c2, c1, c0) VALUES ('m6MkaimUzq', -10811, 'm6MkaimUzq');
INSERT IGNORE  INTO t0(c0) VALUES ('u3pHrhF5LF');

mysql> SELECT * FROM t0 WHERE ((435600036)>=('-'));
+------------+--------+------------+
| c0         | c1     | c2         |
+------------+--------+------------+
| zeGTVmzYyL | -10723 | zeGTVmzYyL |
| m6MkaimUzq | -10811 | m6MkaimUzq |
| u3pHrhF5LF |   NULL | NULL       |
+------------+--------+------------+
3 rows in set, 1 warning (0.00 sec)

mysql> UPDATE t0 SET c0='e9pvumJh2h', c1=3268, c2='e9pvumJh2h' WHERE ((435600036)>=('-'));
ERROR 1292 (22007): Truncated incorrect DOUBLE value: '-'

Suggested fix:
I think you can take a look at Mariadb's solution. Thank you!
[10 Jun 13:39] MySQL Verification Team
HI Mr. Xu,

Thank you for your bug report.

However, this is not a bug.

SQL Standard is very clear on this issue. You should get the error when you compare columns or constants of different data types. Actually, it is prescribed as a very hard error by the latest SQL Standard.

MySQL goes a step further and allows read-only queries to compare the incomparable values. But, only in read-only DML statements. 

Allowing changing data in rows by totally incompatible data types is very grave error. Hence, that is why MySQL will not allow your data to be ruined by the erroneous comparisons of totally different data types.

Hence, the other product is totally unsafe and you should report a bug to them.

Not a bug.