Skip to content

Instantly share code, notes, and snippets.

@andriesss
Created July 31, 2012 12:19
Show Gist options
  • Save andriesss/3216640 to your computer and use it in GitHub Desktop.
Save andriesss/3216640 to your computer and use it in GitHub Desktop.
Conditional on duplicate key update
# A simple example which assumes you have an ENUM('auto', 'manual') column "override" in your table.
INSERT INTO
foo( id, baz, bar )
VALUES
( ?, ?, ? )
ON DUPLICATE KEY UPDATE
baz = IF(override = 'auto', VALUES( baz ), baz),
bar = IF(override = 'auto', VALUES( bar ), bar);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment