Re: Delete duplicates

From: Sean Chittenden <sean(at)chittenden(dot)org>
To: Denis Arh <denis(at)exonium(dot)net>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: Delete duplicates
Date: 2003-06-23 05:22:56
Message-ID: 20030623052256.GS97131@perrin.int.nxad.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

> How to delete "real" duplicates?
>
> id | somthing
> -----------------------
> 1 | aaa
> 1 | aaa
> 2 | bbb
> 2 | bbb
>
> (an accident with backup recovery...)

I'm not 100% on some of the syntax off the top of my head, but:

BEGIN;
ALTER TABLE orig_table RENAME TO backup_table;
CREATE TABLE orig_table AS SELECT id,something FROM backup_table GROUP BY id, something;
-- Create any indexes on orig_table that need to be recreated
DROP TABLE orig_table;
COMMIT;

This isn't for the faint of heart: be sure to do this inside of a
transaction or on a backup db until you're 100% good to go. -sc

--
Sean Chittenden

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Rudi Starcevic 2003-06-23 05:39:24 Re: Delete duplicates
Previous Message Tom Lane 2003-06-23 05:22:34 Re: Delete duplicates