« using procmail and MIME::Parser to extract iphone photo attachments | Main | MT 4.1 »

MySQL Update Evaluation Gotcha

If you use MySQL, note this:


mysql> create database test;
Query OK, 1 row affected (0.01 sec)

mysql> use test;
Database changed
mysql> create table foo (
-> x int,
-> y int
-> );
Query OK, 0 rows affected (0.00 sec)

mysql> insert into foo values (1, 2);
Query OK, 1 row affected (0.00 sec)

mysql> select * from foo;
+------+------+
| x | y |
+------+------+
| 1 | 2 |
+------+------+
1 row in set (0.00 sec)

mysql> update foo set x=5,y=10,x=x+y;
Query OK, 1 row affected (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 0

mysql> select * from foo;
+------+------+
| x | y |
+------+------+
| 15 | 10 |
+------+------+
1 row in set (0.00 sec)

mysql>

I bolded the part that bothers me. No warnings. Double-updating the same value in the same row in the same statement throws no warnings (never mind errors!). I haven't checked the ANSI standard to see if this is mentioned, but it sure is worth noting.

TrackBack

TrackBack URL for this entry:
http://www.mattwallace.net/mt-tb.cgi/66

Comments

oh my.

Post a comment

(If you haven't left a comment here before, you may need to be approved by the site owner before your comment will appear. Until then, it won't appear on the entry. Thanks for waiting.)