I haven’t found a syntax to do this, what I find frustrating is that I haven’t seen anything that specifically says it can’t be done, so I keep searching.
With a table “table_one”, with one unique field “table_one.a” which is the primary key, is it possible to do something like this:
INSERT INTO `table_one` (a,b,c,d,e,f,g,h) VALUES (1,2,3,4,5,6,7,8)
ON DUPLICATE KEY UPDATE VALUES();
I’m aware of the following approaches:
INSERT INTO `table_one` (a,b,c,d,e,f,g,h) VALUES (1,2,3,4,5,6,7,8)
ON DUPLICATE KEY UPDATE `b` = '2', `c` = '3', `d` = '4', `e` = '5', `f` = '6', `g` = '7', `h` = '8';
And
INSERT INTO `table_one` (a,b,c,d,e,f,g,h) VALUES (1,2,3,4,5,6,7,8)
ON DUPLICATE KEY UPDATE `b` = 'VALUES(b)', `c` = 'VALUES(c)', `d` = 'VALUES(d)', `e` = 'VALUES(e)', `f` = 'VALUES(f)', `g` = 'VALUES(g)', `h` = 'VALUES(h)';
I’m hoping that (if it’s not possible) someone can point me to a reference that explains why.
It’s not possible because it violates the
UPDATEsyntax, so you must list every column. You may look into usingREPLACE INTO, but be careful as that actually deletes the row and adds it again, so you may lose some values — it also triggers foreign keyON DELETEs. However, it is a much less verbose way to do what you want.