X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.193]) by svr1.postgresql.org (Postfix) with ESMTP id 5DE9B30F4A1 for ; Mon, 23 Jun 2003 05:23:08 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (svr1.postgresql.org [64.117.224.193]) (amavisd-new, port 10024) with ESMTP id 86142-04 for ; Mon, 23 Jun 2003 02:22:58 -0300 (ADT) Received: from perrin.int.nxad.com (internal.ext.nxad.com [69.1.70.251]) by svr1.postgresql.org (Postfix) with ESMTP id C376330F5C3 for ; Mon, 23 Jun 2003 02:22:57 -0300 (ADT) Received: by perrin.int.nxad.com (Postfix, from userid 1001) id 8FCAC2105E; Sun, 22 Jun 2003 22:22:56 -0700 (PDT) Date: Sun, 22 Jun 2003 22:22:56 -0700 From: Sean Chittenden To: Denis Arh Cc: pgsql-sql@postgresql.org Subject: Re: Delete duplicates Message-ID: <20030623052256.GS97131@perrin.int.nxad.com> References: <20030622091522.M37248@oasis.net.au> <2976.200.59.66.253.1056316636.squirrel@webmail.akyasociados.com.ar> <00ac01c33946$8d1678e0$0a00000a@neo> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <00ac01c33946$8d1678e0$0a00000a@neo> X-PGP-Key: finger seanc@FreeBSD.org X-PGP-Fingerprint: 3849 3760 1AFE 7B17 11A0 83A6 DD99 E31F BC84 B341 X-Web-Homepage: http://sean.chittenden.org/ User-Agent: Mutt/1.5.4i X-Archive-Number: 200306/250 X-Sequence-Number: 14008 > 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