Skip to content

Instantly share code, notes, and snippets.

@MathRobin
Created January 21, 2017 11:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MathRobin/751eff46594ed258d4783bc6680d3308 to your computer and use it in GitHub Desktop.
Save MathRobin/751eff46594ed258d4783bc6680d3308 to your computer and use it in GitHub Desktop.
WITH upsert AS
(UPDATE maTable
SET monChamp = 'nouvelleValeur';
WHERE monId = cetId
RETURNING *)
INSERT INTO maTable
(monId, monChamp)
SELECT cetId, 'nouvelleValeur'
WHERE NOT EXISTS (SELECT * FROM upsert);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment