I have a program that needs to synchronize it's frequently changing values (in temporary memory) with a database. The critical key (not primary!) in that table is the column id. My program changes the id but keeps the old id in memory, too.
Now, I would like to update several specified columns for multiple records/rows in one single statement. Furthermore, it should be reasonably fast for 5 up to 10 of such statements in 1 second with 4 GB RAM and ~ 50 MBit/s connection that is not only used for these sql-calls.
My sql-specifications
- Server: 127.0.0.1 via
- TCP/IP
- Software: MySQL
- Software version: 5.5.27 - MySQL Community Server (GPL)
- Protocol version: 10
- Server charset: UTF-8 Unicode (utf8)
I tried to use brackets...
UPDATE someTable
SET (id, name) = CASE id
WHEN 1 THEN (111, "Dr. Frankenstein")
WHEN 2 THEN (222, "the Monster")
WHEN 3 THEN (333, "Mr. X")
ELSE (id, name) END
WHERE id IN (1, 2, 3)
...which simply results in the following error:
#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '(id, name) = CASE id WHEN 1 THEN (111, "Dr. Frankenstein") WHEN 2 THEN (222,' at line 2
Know I wonder: Is there a way to do it in just one statement with the current syntax? Would it be feasable that way or should I just split it into multiple statement which is ugly in terms of the program that makes the sql-calls.
Answers and suggestions are welcome!