Delete duplicate records from postgres table

suggest change
DELETE FROM <SCHEMA_NAME>.<TABLE_NAME>
WHERE ctid NOT IN (
    SELECT MAX(ctid)
    FROM <SCHEMA_NAME>.<TABLE_NAME>
    GROUP BY <column_list>
);

ctid identifies the physical row for this statement only. GROUP BY needs the columns that define a duplicate; table.* is not valid there. One row in each group is kept. Add a WHERE clause inside the subquery if only some duplicates should be removed.

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents