Skip to content

Instantly share code, notes, and snippets.

@martjanz
Created March 20, 2015 00:21
Show Gist options
  • Save martjanz/df81fe29ae00c3c1e1b3 to your computer and use it in GitHub Desktop.
Save martjanz/df81fe29ae00c3c1e1b3 to your computer and use it in GitHub Desktop.
Delete duplicate rows (PostgreSQL)
-- Works OK in PostgreSQL 9.3
DELETE FROM table_name
WHERE ctid NOT IN
(SELECT MAX(ctid)
FROM
table_name t
GROUP BY
t.column_1, t.column_2; -- t.* for completely duplicate rows
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment