Bug #105350 Data insertion exception in version 8.0.27

Submitted: 28 Oct 2021 2:06 Modified: 28 Oct 2021 2:13
Reporter: tuantuan Xue Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server Severity:S3 (Non-critical)
Version:8.0.27 OS:Any
Assigned to: CPU Architecture:Any

[28 Oct 2021 2:06] tuantuan Xue
Description:
We found a serious problem. When inserting with insert select statement, there are data exceptions。

How to repeat:

CREATE TABLE test(ID INT,FIELDNAME VARCHAR(100));
INSERT INTO test VALUES(1,'36245');

The result of the query is displayed:

SELECT 
  MAX(id)+1 ,
  '27141' id2
FROM
  test a 
  GROUP BY id2 ;

----------------------------------------
MAX(id)+1  id2     
---------  --------
        2  27141   

However, if you insert this result into the test table:
INSERT INTO test 
SELECT 
  MAX(id)+1 ,
  '27141' id2
FROM
  test a 
  GROUP BY id2 ;

select * from test;

    ID  FIELDNAME  
------  -----------
     1  36245      
(NULL)  27141      

The ID of the data inserted above turned out to be null

Suggested fix:
We changed the way we wrote the sentence, but it was correct:

INSERT INTO test 
SELECT 
  MAX(id+1),
  '27141' id2
FROM
  test a 
  GROUP BY id2
[28 Oct 2021 2:11] tuantuan Xue
thx
[28 Oct 2021 2:13] tuantuan Xue
Repetitive

Portions of this website are copyright © 2001, 2002 The PHP Group

Page generated in 0.050 sec. using MySQL 8.4.7-u6-cloud

Timestamp references displayed by the system are UTC.
Content reproduced on this site is the property of the respective copyright holders.
It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.