Deleting duplicate records

Started by Bob Powellalmost 23 years ago2 messagesgeneral
Jump to latest
#1Bob Powell
Bob@hotchkiss.org

Hello everyone:

Can someone tell me if there is a way to delete duplicate records from a table in Postgres.

I once used a database management system that had a "Delete Duplicates" which would check every field in the row and if they all matched would delete the row. You could also designate the fields you wanted the command to use to check for dups. Very nice feature. Maybe something for the TODO list?

Bob Powell

#2Dmitry Tkach
dmitry@openratings.com
In reply to: Bob Powell (#1)
Re: Deleting duplicate records

Bob Powell wrote:

Hello everyone:

Can someone tell me if there is a way to delete duplicate records from a table in Postgres.

I once used a database management system that had a "Delete Duplicates" which would check every field in the row and if they all matched would delete the row. You could also designate the fields you wanted the command to use to check for dups. Very nice feature. Maybe something for the TODO list?

As generally as you state the problem, something like this comes to mind:

select distinct * into temp unique_rows from table_to_cleanup;
truncate table_to_cleanup;
insert into table_to_cleanup select * from unique_rows;

I hope, it helps...

Dima

Show quoted text

Bob Powell

---------------------------(end of broadcast)---------------------------
TIP 5: Have you checked our extensive FAQ?

http://www.postgresql.org/docs/faqs/FAQ.html