Skip to content

Instantly share code, notes, and snippets.

@MathRobin MathRobin/upsert.sql
Created Jan 21, 2017

Embed
What would you like to do?
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
You can’t perform that action at this time.