Bug #11687 Weird return from last_insert_id()
Submitted: 1 Jul 2005 12:29 Modified: 1 Jul 2005 15:25
Reporter: Espen Skogen Email Updates:
Status: Can't repeat Impact on me:
None 
Category:MySQL Server Severity:S2 (Serious)
Version:4.1.10 OS:Linux (Redhat Linux)
Assigned to: CPU Architecture:Any

[1 Jul 2005 12:29] Espen Skogen
Description:
create table t1 (id int unsigned auto_increment primary key);

create table t2 (a int, b int);

insert into t1 values(null);
insert into t2 values(1, last_insert_id());

select * from t1

id
--
1

select * from t2

a | b 
------
1 | 0 

So for some reason last_insert_id() is returning 0 even though last insert id
was 1.

Any ideas? I saw this issue referred to as a bug somewhere else - Is there any
patches for this?

Any help would be good.

Thanks.
E

How to repeat:
create table t1 (id int unsigned auto_increment primary key);

create table t2 (a int, b int);

insert into t1 values(null);
insert into t2 values(1, last_insert_id());

select * from t1

id
--
1

select * from t2

a | b 
------
1 | 0
[1 Jul 2005 15:25] MySQL Verification Team
I wasn't able to repeat it with 4.1.13.

mysql> create table t1 (id int unsigned auto_increment primary key);
Query OK, 0 rows affected (0.06 sec)

mysql>
mysql> create table t2 (a int, b int);
Query OK, 0 rows affected (0.07 sec)

mysql>
mysql> insert into t1 values(null);
Query OK, 1 row affected (0.00 sec)

mysql> insert into t2 values(1, last_insert_id());
Query OK, 1 row affected (0.00 sec)

mysql>
mysql> select * from t1;
+----+
| id |
+----+
|  1 |
+----+
1 row in set (0.00 sec)

mysql> select * from t2;
+------+------+
| a    | b    |
+------+------+
|    1 |    1 |
+------+------+
1 row in set (0.00 sec)