Skip to content

Instantly share code, notes, and snippets.

@lv10
Last active August 29, 2015 14:02
Show Gist options
  • Save lv10/d9a94f6a949e65a9323a to your computer and use it in GitHub Desktop.
Save lv10/d9a94f6a949e65a9323a to your computer and use it in GitHub Desktop.
Delete duplicates from a table without primary key SQL
DELETE FROM claim_rates
WHERE ctid IN (SELECT
ctid
FROM (SELECT
ctid,
ROW_NUMBER()
OVER (
PARTITION BY claim_tag, rate_type, pricing_record_id
ORDER BY claim_tag, rate_type, pricing_record_id) AS rnum
FROM claim_rates) t
WHERE t.rnum > 1);
Documentation here:
http://wiki.postgresql.org/wiki/Deleting_duplicates
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment