Created
July 31, 2012 12:19
-
-
Save andriesss/3216640 to your computer and use it in GitHub Desktop.
Conditional on duplicate key update
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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