Skip to content

Instantly share code, notes, and snippets.

@ostronom
Last active September 8, 2016 12:48
Show Gist options
  • Save ostronom/0138a6b9ecc440d93c0c9ebc00396ad8 to your computer and use it in GitHub Desktop.
Save ostronom/0138a6b9ecc440d93c0c9ebc00396ad8 to your computer and use it in GitHub Desktop.
-- CREATE TABLE t (id bigint primary key, c bigint not null)
BEGIN;
UPDATE t SET c=1 WHERE id=1;
INSERT INTO t (id, c) SELECT 1, 1 WHERE NOT EXISTS (SELECT 1 FROM t WHERE id=1);
END;
-- pg 9.4.8
-- contraint violation: duplicate key `id`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment