Skip to content

Instantly share code, notes, and snippets.

@sgraham785
Created March 23, 2018 15:45
Show Gist options
  • Save sgraham785/abd9ff294b6bcc1ee0236ced4e62e89a to your computer and use it in GitHub Desktop.
Save sgraham785/abd9ff294b6bcc1ee0236ced4e62e89a to your computer and use it in GitHub Desktop.
Examples of PostgreSQL Upsert
INSERT INTO users (id, level)
VALUES (1, 0)
ON CONFLICT (id) DO UPDATE
SET level = users.level + 1;
INSERT INTO users (id, email)
VALUES (1, somenew@email.com)
ON CONFLICT (id) DO UPDATE
SET email = EXCLUDED.email;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment