Thread: Deleting duplicate records

Deleting duplicate records

From
"Bob Powell"
Date:
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
theyall 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



Re: Deleting duplicate records

From
Dmitry Tkach
Date:
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
ifthey all matched would delete the row.  You could also designate the fields you wanted the command to use to check
fordups.  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


>Bob Powell
>
>
>
>---------------------------(end of broadcast)---------------------------
>TIP 5: Have you checked our extensive FAQ?
>
>http://www.postgresql.org/docs/faqs/FAQ.html
>
>