MySQL Forums
Forum List  »  Docs

auto_increment column is null
Posted by: Egor
Date: January 27, 2009 11:23AM

I've found that select of "auto_increment column is null" gives the first inserted row of the last insert, once the select runs right after the insert.
The behaviour take place at least for MyISAM and InnoDB engines for 4.1.22 and 5.0.32 versions of MySQL.

mysql> create table foo (
-> id int not null auto_increment,
-> val char(10),
-> primary key (id)
-> ) ENGINE=MyISAM;
Query OK, 0 rows affected (0.01 sec)

mysql> insert into foo (val) values ('bar'), ('baz');
Query OK, 2 rows affected (0.00 sec)
Records: 2 Duplicates: 0 Warnings: 0

mysql> select * from foo where id is null;
+----+------+
| id | val |
+----+------+
| 1 | bar |
+----+------+
1 row in set (0.00 sec)

mysql> select * from foo where id is null;
Empty set (0.00 sec)


Is the following feature documented anywhere?
Is there a way to turn off the feature?

Options: ReplyQuote


Subject
Views
Written By
Posted
auto_increment column is null
8236
January 27, 2009 11:23AM
3608
February 18, 2009 12:27PM


Sorry, you can't reply to this topic. It has been closed.

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.