Starting from MySQL execution update error ERROR 1292

157202a8d942e29df0356f05d93f000a.gif

Author | JiekeXu

Source|Public Account JiekeXu DBA Road (ID: JiekeXu_IT)

If you need to reprint, please contact for authorization | (Personal WeChat ID: JiekeXu_DBA)

Hello everyone, I am JiekeXu. I am very glad to meet you again. Today, I will take a look at MySQL execution update and report error ERROR 1292. Please click on the blue word "JiekeXu DBA Road" above to follow my official account, star or pin it to the top , more dry goods will arrive as soon as possible!

The thing is like this, when I used the automated tool to execute the SQL written by the developer before work last Friday, the automated tool failed to execute, so I manually went to the production environment to execute it, and an error occurred "ERROR 1292 (22007): Truncated incorrect DOUBLE value” to truncate the incorrect DOUBLE value . Is it because the length of the data type is not enough? Next, let’s check the table structure.

mysql> update t_busi_cont set busi_contract_file='ba42cfdb-a1d0-4e5a-c'  and busi_contract_file_ct=1 
    -> where id='7823dcaade9145cdb8702d537';
ERROR 1292 (22007): Truncated incorrect DOUBLE value: 'ba42cfdb-a1d0-4e5a-c'




mysql> select busi_contract_file,busi_contract_file_ct from t_busi_cont where id='7823dcaade9145cdb8702d537';
+------------------------------------------------+-----------------------+
| busi_contract_file                             | busi_contract_file_ct |
+------------------------------------------------+-----------------------+
| undefined,ba42cfdb-a1d0-4e5a-c                 |                     2 |
+------------------------------------------------+-----------------------+

Looking at the table structure, there is nothing wrong with these two field types, character type and integer type, and varchar(4000). . . . . .

mysql> show create table t_busi_cont;
CREATE TABLE `t_busi_cont` (
  `sequence_no` int(18) NOT NULL AUTO_INCREMENT COMMENT '顺序号',
  `id` varchar(36) COLLATE utf8mb4_bin NOT NULL COMMENT '合同明细编号',
  `busi_contract_file` varchar(4000) COLLATE utf8mb4_bin DEFAULT NULL COMMENT '合同文件编号,逗号分隔',
  `busi_contract_file_ct` int(10) NOT NULL DEFAULT '0' COMMENT '合同文件张数',
  ……省去其他字段……
  PRIMARY KEY (`sequence_no`),
  UNIQUE KEY `u_t_ar_busi_contract_01` (`id`),
  );

Then use the client-side visualization tool and the Xshell command line to execute the same error. There is no other way. Let’s update separately according to the SQL logic. The separate update according to the conditions is considered a success. I haven’t thought it is a grammar problem until here. . . . . .

mysql> update t_busi_cont set busi_contract_file='ba42cfdb-a1d0-4e5a-c' where id='7823dcaade9145cdb8702d537';
Query OK, 1 row affected (25.12 sec)
Rows matched: 1  Changed: 1  Warnings: 0
mysql> commit;
Query OK, 0 rows affected (0.01 sec)
mysql> update t_busi_cont set busi_contract_file_ct=1  where id='7823dcaade9145cdb8702d537';
Query OK, 1 row affected (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 0
mysql> commit;
Query OK, 0 rows affected (0.01 sec)

In the verification stage, I didn’t want to understand it for a while, so I found a test environment and simulated the update logic. As shown below, the update was successful. But judging from the update results below, only updating the value of id=1 to 0 does not update column c to 6, which is not as expected. If you want to update the values ​​of multiple columns, you cannot use AND, you can use commas to separate them. Although the error is because of the syntax of the clause, the MySQL error description also misleads me into thinking that there is a problem with the value. One of the reasons for triggering this error is that the AND clause is used when updating multiple columns of the table without using commas to separate multiple columns. .

Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 48
Server version: 8.0.28 MySQL Community Server - GPL


Copyright (c) 2000, 2022, Oracle and/or its affiliates.


Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.


Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.


mysql> select * from t;
+----+------+------+
| id | c    | d    |
+----+------+------+
|  1 |    1 |    1 |
|  2 |    2 |    2 |
|  3 |    3 |    3 |
|  4 |    4 |    4 |
|  5 |    5 |    4 |
+----+------+------+
5 rows in set (0.00 sec)


mysql> update t set id=6 and c=6 where d=1;    ----AND 连接
Query OK, 1 row affected (0.06 sec)
Rows matched: 1  Changed: 1  Warnings: 0


mysql> select * from t;
+----+------+------+
| id | c    | d    |
+----+------+------+
|  0 |    1 |    1 |
|  2 |    2 |    2 |
|  3 |    3 |    3 |
|  4 |    4 |    4 |
|  5 |    5 |    4 |
+----+------+------+
5 rows in set (0.00 sec)


mysql> update t set id=6,c=6 where d=1;  ----使用逗号分隔
Query OK, 1 row affected (0.01 sec)
Rows matched: 1  Changed: 1  Warnings: 0


mysql> select * from t;
+----+------+------+
| id | c    | d    |
+----+------+------+
|  2 |    2 |    2 |
|  3 |    3 |    3 |
|  4 |    4 |    4 |
|  5 |    5 |    4 |
|  6 |    6 |    1 |
+----+------+------+
5 rows in set (0.00 sec)

58c1e50786bf5494399bb1c5ec0f52e0.png

In the test shown above, "update t set id=6 and c=6 where d=1;" actually succeeded, but there is a problem, you don't know if you have thought about it, why is the value updated to 0? You can think about it first. If you can’t think of it for the time being, you can continue to look at the picture below.

de32a41699d53f23e944fe1d4bf1f12e.png

Do you see clearly? In the figure above, "update t set id='6' and c='6' where d=1;" and "update t set id='6' and c='1' where d=1;" are executed successfully , but the value of the successful update is different, the front is 1 and the back is 0, do you think of it now? 0, 1, 0, 1 Isn’t this a Boolean value? In MySQL, the optimizer treats the clause between "set id=" and where as a value, and the result of '6' and c='6' is It is considered to be true, so it is updated to id=1, the result of '6' and c='1' is considered false, so it is updated to id=0 (but I still don't understand why it is this result, If someone sees it, you can give me a lesson), but in the production environment, the wrong data type in the picture below does not match and an error is reported, but this error message is a bit confusing.

2e950d26bcdd049ca424556306789b94.png

In my Oracle 23c test environment, I simulated the above operation, and when I executed this SQL directly, an error was reported, and the operation was invalid ORA-00920.

Connected to:
Oracle Database 23c Free, Release 23.0.0.0.0 - Developer-Release
Version 23.2.0.0.0


SQL> CREATE TABLE JiekeXu.t1 (
  2    id int NOT NULL,
  3    c int DEFAULT NULL,
  4    d int DEFAULT NULL,
  5    PRIMARY KEY (id)
  6  );


Table created.


SQL> insert into JiekeXu.t1 values(1,1,1),(2,2,2),(3,3,3);    ----23c 新特性允许一次性插入多行值


3 rows created.


SQL> commit;


Commit complete.


SQL> select * from JiekeXu.t1;


        ID          C          D
---------- ---------- ----------
         1          1          1
         2          2          2
         3          3          3


SQL> update JiekeXu.t1 set id=6 and c=6 where d=1;
update JiekeXu.t1 set id=6 and c=6 where d=1
                           *
ERROR at line 1:
ORA-00920: invalid relational operator




SQL> update JiekeXu.t1 set id=6,c=6 where d=1;
1 row updated.

bf213a62032a4c99fa806b29d15574e5.png

Next, I also tested that the PostgreSQL 14 version will also report an error directly, and the error message is very obvious ERROR:argument of AND must be type boolean, not type integer , AND must be followed by a boolean type instead of an integer type.

73955c42b9ff7ce69ff46a4570cdc2de.png

$ psql
psql (14.1)
Type "help" for help.
postgres=# \c jiekexu
You are now connected to database "jiekexu" as user "postgres".
jiekexu=# \dt 
             List of relations
 Schema |     Name      | Type  |  Owner   
--------+---------------+-------+----------
 public | t             | table | postgres
 public | t1            | table | postgres
 public | t_analyzeplan | table | postgres
(3 rows)


jiekexu=# CREATE TABLE test (
jiekexu(#       id int NOT NULL,
jiekexu(#       c int DEFAULT NULL,
jiekexu(#       d int DEFAULT NULL,
jiekexu(#       PRIMARY KEY (id)
jiekexu(#     );
CREATE TABLE
jiekexu=# insert into test values(1,1,1),(2,2,2),(3,3,3);
INSERT 0 3
jiekexu=# 
jiekexu=# select * from test;
 id | c | d 
----+---+---
  1 | 1 | 1
  2 | 2 | 2
  3 | 3 | 3
(3 rows)


jiekexu=#  update test set id=6 and c=6 where d=1;
ERROR:  argument of AND must be type boolean, not type integer
LINE 1: update test set id=6 and c=6 where d=1;
                           ^
jiekexu=# show server_version;
 server_version 
----------------
 14.1
(1 row)

40a293685a83834f0aa563164e718773.png

The full text is finished, I hope it can help you who are reading, if you think this article is helpful to you, you can share it with your friends, colleagues, whoever you care about, and share it with whoever you care about, let's learn together and make progress~~~

Welcome to follow my official account [JiekeXu DBA Road], and learn new knowledge together as soon as possible! You can find me at the following three addresses. The other addresses belong to pirated copyright infringement crawling my articles, and the code format, pictures, etc. are disordered, which is inconvenient to read. Welcome to my official account or Motianlun address to follow me, and get the latest updates as soon as possible information.

————————————————————————————————
Public account: JiekeXu DBA Road
CSDN: https://blog.csdn.net/JiekeXu
Motian Wheel: https://www.modb.pro/u/4347
———————————————————————————————

1212dbcc0b5d69618025af28c9833b74.gif

Share several database backup scripts

Oracle table fragmentation check and defragmentation scheme

OGG|Oracle GoldenGate 基础2022 年公众号历史文章合集整理
 
  

Several problems encountered by Oracle 19c RAC

OGG|Oracle 数据迁移后比对一致性

OGG|Oracle GoldenGate Microservice Architecture

Oracle query table space usage is extremely slow

Domestic database|TiDB 5.4 stand-alone quick installation first experience

Oracle ADG standby database shutdown maintenance process and incremental recovery

Linux environment to build MySQL8.0.28 master-slave synchronization environment

bb5d1f0f8c0856d6055aeade49b23366.png

Guess you like

Origin blog.csdn.net/JiekeXu/article/details/131651113