Skip to content

Instantly share code, notes, and snippets.

@evervasquez
Created April 28, 2019 00:57
Show Gist options
  • Save evervasquez/b7c904f7e5573dfdc08c38ec15d96827 to your computer and use it in GitHub Desktop.
Save evervasquez/b7c904f7e5573dfdc08c38ec15d96827 to your computer and use it in GitHub Desktop.
Eliminate duplicate records
WITH tableunica AS
(SELECT table1.id, min(ctid)
FROM table1
GROUP BY 1 HAVING count(*) > 1)
DELETE FROM table1
USING tableunica
WHERE (table1.id)=(tableunica.id)
AND table1.ctid <> tableunica.min
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment