Bug #76393 | Update query stores one value before evaluation equation for second | ||
---|---|---|---|
Submitted: | 19 Mar 2015 17:41 | Modified: | 19 Mar 2015 19:03 |
Reporter: | Ben Kaap | Email Updates: | |
Status: | Verified | Impact on me: | |
Category: | MySQL Server: DML | Severity: | S3 (Non-critical) |
Version: | 5.6.23 | OS: | Any |
Assigned to: | CPU Architecture: | Any | |
Tags: | UPDATE SET IF CASE |
[19 Mar 2015 17:41]
Ben Kaap
[19 Mar 2015 19:03]
MySQL Verification Team
I have tested this with latest 5.6 and 5.7 and behavior is the same. I have also tested it with MyISAM and InnoDB and it is still the same. Fully verified.
[20 Mar 2015 11:29]
Roy Lyseng
This is actually the documented behavior. Quoting from the manual: If you access a column from the table to be updated in an expression, UPDATE uses the current value of the column. For example, the following statement sets col1 to one more than its current value:  UPDATE t1 SET col1 = col1 + 1; The second assignment in the following statement sets col2 to the current (updated) col1 value, not the original col1 value. The result is that col1 and col2 have the same value. This behavior differs from standard SQL. UPDATE t1 SET col1 = col1 + 1, col2 = col1; Single-table UPDATE assignments are generally evaluated from left to right. For multiple-table updates, there is no guarantee that assignments are carried out in any particular order. It is quite unfortunate that we do not support standard SQL here, so this should be a valid feature request.