Created
March 25, 2019 06:56
-
-
Save varunchitale/39f137da733f418c5d9939e29c28242c to your computer and use it in GitHub Desktop.
Efficiently delete duplicates rows from a table with a set of specific constraints.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
DELETE FROM <table> a USING ( | |
SELECT MIN(ctid) as ctid, var1, var2 | |
FROM <same_table> b | |
GROUP BY 2,3 HAVING COUNT(*) > 1 | |
) b | |
WHERE a.var1 = b.var1 | |
and a.var2 = b.var2 | |
AND a.ctid <> b.ctid |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment