Skip to content

Instantly share code, notes, and snippets.

@jamesplease
Last active March 19, 2017 19:02
Show Gist options
  • Save jamesplease/280df5ff1339a0e98b139fa8ebd5c195 to your computer and use it in GitHub Desktop.
Save jamesplease/280df5ff1339a0e98b139fa8ebd5c195 to your computer and use it in GitHub Desktop.
Upsert in Postgres. Will create nonexistent rows so not so useful for relationship updates
INSERT INTO the_table (id, column_1, column_2)
VALUES (1, 'A', 'X'), (2, 'B', 'Y'), (3, 'C', 'Z')
ON CONFLICT (id) DO UPDATE
SET column_1 = excluded.column_1,
column_2 = excluded.column_2;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment