Bug #45231 | Cannot change LAST_INSERT_ID value within before update trigger | ||
---|---|---|---|
Submitted: | 1 Jun 2009 3:07 | Modified: | 1 Jun 2009 20:29 |
Reporter: | Dennis Birkholz | Email Updates: | |
Status: | Verified | Impact on me: | |
Category: | MySQL Server: Stored Routines | Severity: | S4 (Feature request) |
Version: | 5.0.60 | OS: | Any |
Assigned to: | CPU Architecture: | Any | |
Tags: | LAST_INSERT_ID, trigger |
[1 Jun 2009 3:07]
Dennis Birkholz
[1 Jun 2009 6:42]
Sveta Smirnova
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 Please also read at http://dev.mysql.com/doc/refman/5.0/en/information-functions.html#function_last-insert-id: "LAST_INSERT_ID() (with no argument) returns the first automatically generated value that was set for an AUTO_INCREMENT column by the most recently executed INSERT statement to affect such a column. " In your case you set this value explicitly, so it can not be considered automatically generated.
[1 Jun 2009 16:39]
Dennis Birkholz
Because a feature is documented it is not necessarily the correct behaviour, it may also be a bug to the majority of the users! I am aware of the documentation on mysql.com, but it seems to me that not much people actually use triggers so this problem has not occured very often to other people. I can live with a change to feature request with the following actual "request": If LAST_INSERT_ID(XXX) is used inside a BEFORE INSERT trigger and the trigger sets an auto_increment column that normaly would be filled by a computed value, a call to LAST_INSERT_ID after the BEFORE INSERT trigger has finished should return the value written by the trigger. Nevertheless thank you for a great product!
[1 Jun 2009 20:29]
Sveta Smirnova
Thank you for the feedback. Verified as feature request, although I personally like more simple and predictable behavior of functions. Current workaround: use user variables (these which can be set like SET @last_insert_id) or temporary table and update it from the trigger.