Details
-
Bug
-
Status: Closed (View Workflow)
-
Minor
-
Resolution: Not a Bug
-
10.5.9
-
None
-
centos
Description
Using RETURNING get the wrong last_insert_id(). I am not sure if this is a correct semantic.
How to repeat:
MariaDB [test]> create table t (id INT NOT NULL auto_increment, s varchar(255),primary key(id));
|
Query OK, 0 rows affected (0.01 sec)
|
|
MariaDB [test]> insert into t (s) values ("abc");
|
Query OK, 1 row affected (0.00 sec)
|
|
MariaDB [test]> select last_insert_id();
|
+------------------+
|
| last_insert_id() |
|
+------------------+
|
| 1 |
|
+------------------+
|
1 row in set (0.00 sec)
|
|
MariaDB [test]> insert into t (s) values ("bcd") returning *, last_insert_id();
|
+----+------+------------------+
|
| id | s | last_insert_id() |
|
+----+------+------------------+
|
| 2 | bcd | 1 |
|
+----+------+------------------+
|
1 row in set (0.01 sec)
|
|
MariaDB [test]> select last_insert_id();
|
+------------------+
|
| last_insert_id() |
|
+------------------+
|
| 2 |
|
+------------------+
|
1 row in set (0.00 sec)
|
|
MariaDB [test]>
|
As we can see, we can't get the latest last_insert_id() using returning.