Bug #20657 | wrong auto_increment value returns on "ON DUPLICATE KEY UPDATE" | ||
---|---|---|---|
Submitted: | 23 Jun 2006 12:31 | Modified: | 23 Jun 2006 12:47 |
Reporter: | Michael Rack | Email Updates: | |
Status: | Duplicate | Impact on me: | |
Category: | MySQL Server | Severity: | S2 (Serious) |
Version: | 5.1.11 | OS: | GNU Linux |
Assigned to: | CPU Architecture: | Any |
[23 Jun 2006 12:31]
Michael Rack
[23 Jun 2006 12:47]
Guilhem Bichot
Hello! The "affected rows 2" is normal, it helps the user know if the row was inserted or updated (here it was updated). You'd want last_insert_id() to return 1, it's like in BUG#19243; we are looking into this (per the documentation, last_insert_id() needn't return the id of an *updated* row, only of an *inserted* one, but I agree it can make sense to do so). Until we know if we can change from 2 to 1, you can work around the problem by using mysql_insert_id() (a function from the C API, which also has equivalents in Perl's DBI, PHP, ...).