Re: Delete duplicates - Mailing list pgsql-sql

From Sean Chittenden
Subject Re: Delete duplicates
Date
Msg-id 20030623052256.GS97131@perrin.int.nxad.com
Whole thread Raw
In response to Re: Delete duplicates  ("Denis Arh" <denis@exonium.net>)
List 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


pgsql-sql by date:

Previous
From: "Denis Arh"
Date:
Subject: Re: Delete duplicates
Next
From: Tom Lane
Date:
Subject: Re: Delete duplicates