Bug #21722 | bug with '0' (zero) value in a field of type auto_increment and alter table | ||
---|---|---|---|
Submitted: | 18 Aug 2006 14:37 | Modified: | 23 Sep 2006 11:10 |
Reporter: | Frederic linot | Email Updates: | |
Status: | Not a Bug | Impact on me: | |
Category: | MySQL Server | Severity: | S2 (Serious) |
Version: | mysql Ver 14.12 Distrib 5.0.18 | OS: | pc-linux-gnu (i686) |
Assigned to: | CPU Architecture: | Any | |
Tags: | 0, auto_increment |
[18 Aug 2006 14:37]
Frederic linot
[18 Aug 2006 14:59]
Jon Stephens
Thank you for taking the time to write to us, but this is not a bug. Please double-check the documentation available at http://dev.mysql.com/doc/ and the instructions on how to report a bug at http://bugs.mysql.com/how-to-report.php As stated at http://dev.mysql.com/doc/refman/5.0/en/create-table.html: > An integer column can have the additional attribute AUTO_INCREMENT. When you > insert a value of NULL (recommended) or 0 into an indexed AUTO_INCREMENT > column, the column is set to the next sequence value.
[29 Aug 2006 14:16]
Frederic linot
I didn't knew about this specificity. But imagine you want to dump a such table : +----+----------+------------------------------+ | id | libelle | site_internet | +----+----------+------------------------------+ | 6 | Boss | http://www.bossus.com/ | | 11 | Creative | http://www.creative.com/ | | 0 | empty | | +----+----------+------------------------------+ if you use the mysqldump command, you will obtain the code : INSERT INTO `table` (`id`, `libelle`, `site_internet`) VALUES (6,'Boss','http://www.bossus.com/'),(11,'Creative','http://www.creative.com/'),(0,'empty','';) Imagine now that you want to import your dump into a new database ! Your table will be : +----+----------+------------------------------+ | id | libelle | site_internet | +----+----------+------------------------------+ | 6 | Boss | http://www.bossus.com/ | | 11 | Creative | http://www.creative.com/ | | 12 | empty | | +----+----------+------------------------------+ DO YOU THINK THIS IS AN EXPECTED BEHAVIOR ???
[22 Sep 2006 16:09]
Frederic linot
consider a field named "f" of type INTEGER, autoincrement. You have a row with the number 0 inside. now, you do a "ALTER TABLE t ORDER BY f" THE ROW WITH THE INITIAL NUMBER 0 IS NOW RE-ORDERED AND SET TO THE NEXT AUTOINCREMENT VALUE !! O_O
[22 Sep 2006 16:10]
Frederic linot
consider a field named "f" of type INTEGER, autoincrement. You have a row with the number 0 inside. now, you do a "ALTER TABLE t ORDER BY f" THE ROW WITH THE INITIAL NUMBER 0 IS NOW RE-ORDERED AND SET TO THE NEXT AUTOINCREMENT VALUE !! O_O
[23 Sep 2006 11:10]
Valeriy Kravchuk
Still not a bug. If you need 0 to be stored in auto_increment column and processed "correctly", just use SQL mode NO_AUTO_VALUE_ON_ZERO. Read http://dev.mysql.com/doc/refman/5.0/en/server-sql-mode.html for the details.