Removing duplicates

From: Bruno Wolff III <bruno(at)wolff(dot)to>
To: Surabhi Ahuja <surabhi(dot)ahuja(at)iiitb(dot)ac(dot)in>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Removing duplicates
Date: 2005-02-08 20:52:43
Message-ID: 20050208205243.GA23077@wolff.to
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Please use a relevant subject for your posts.

On Tue, Feb 08, 2005 at 23:14:57 +0530,
Surabhi Ahuja <surabhi(dot)ahuja(at)iiitb(dot)ac(dot)in> wrote:
> i have a table in which duplicate rows occur.
>
> now i have to remove the duplicates. Please note that however, only the duplicate rows have to be deleted and not the original one.
>
> How do i do it?

If the table has oids, then you can delete all but the row with the minimum
oid for each set of duplicates.

Another option is to do a select distinct into a temp table, a delete and
then copy the temp table back.

You should also add a constraint so that duplicates can't get back into
the table once you have it cleaned up.

In response to

  • at 2005-02-08 17:44:57 from Surabhi Ahuja

Browse pgsql-general by date

  From Date Subject
Next Message Vivek Khera 2005-02-08 20:57:56 Re: Safely Killing Backends
Previous Message Vivek Khera 2005-02-08 20:49:42 Re: pgpool simple feature request