Re: How to delete duplicate rows?

From: Bruno Wolff III <bruno(at)wolff(dot)to>
To: Clodoaldo Pinto <clodoaldo(dot)pinto(at)gmail(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: How to delete duplicate rows?
Date: 2005-02-04 14:18:16
Message-ID: 20050204141816.GC18206@wolff.to
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Thu, Feb 03, 2005 at 23:04:57 -0200,
Clodoaldo Pinto <clodoaldo(dot)pinto(at)gmail(dot)com> wrote:
> This one must be obvious for most here.
>
> I have a 170 million rows table from which I want to eliminate
> duplicate "would be" keys and leave only uniques.
>
> I found a query in http://www.jlcomp.demon.co.uk/faq/duplicates.html
> for the oracle database but can't figure out how to refer to the row
> id in postgresql:
>
> delete from test where rowid not in
> (select min(rowid) from test group by a,b);
>
> How to refer to the row id? Any better way to do it?

Your best bet is to use oid if the table has them. If it doesn't you
might want to use ctid. That will require creating some comparison
functions that don't exist by default. By the time you write and test
those, the select distinct method you actually used might be better.

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Sean Davis 2005-02-04 14:35:59 Re: mysql load_file() function
Previous Message Shridhar Daithankar 2005-02-04 14:16:35 Re: mysql load_file() function