Skip to content

Instantly share code, notes, and snippets.

@andybeak
Created March 30, 2015 14:59
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 andybeak/750afee1bccd3e3fddf3 to your computer and use it in GitHub Desktop.
Save andybeak/750afee1bccd3e3fddf3 to your computer and use it in GitHub Desktop.
Ignore duplicate inserts in Postgre SQL
CREATE OR REPLACE RULE db_table_ignore_duplicate_inserts AS
ON INSERT TO db_table
WHERE (EXISTS ( SELECT 1
FROM db_table
WHERE db_table.tbl_column = NEW.tbl_column)) DO INSTEAD NOTHING;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment