Received: from maia.hub.org (maia-5.hub.org [200.46.204.29]) by mail.postgresql.org (Postfix) with ESMTP id C9CB3633818 for ; Tue, 10 Aug 2010 16:44:44 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.29]) (amavisd-maia, port 10024) with ESMTP id 76370-01 for ; Tue, 10 Aug 2010 19:44:37 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from vs137086.vserver.de (static-ip-62-75-137-86.inaddr.intergenia.de [62.75.137.86]) by mail.postgresql.org (Postfix) with ESMTP id 04548632C10 for ; Tue, 10 Aug 2010 16:44:36 -0300 (ADT) Received: (qmail 32570 invoked from network); 10 Aug 2010 21:44:34 +0200 Received: from p57aadc04.dip.t-dialin.net (HELO a-kretschmer.de) (87.170.220.4) by static-ip-62-75-137-86.inaddr.intergenia.de with (AES256-SHA encrypted) SMTP; 10 Aug 2010 21:44:34 +0200 Received: from kretschmer by a-kretschmer.de with local (Exim 4.69) (envelope-from ) id 1OiukT-0000aE-4K for pgsql-sql@postgresql.org; Tue, 10 Aug 2010 21:44:33 +0200 Date: Tue, 10 Aug 2010 21:44:33 +0200 From: Andreas Kretschmer To: pgsql-sql@postgresql.org Subject: Re: Duplicate rows Message-ID: <20100810194433.GA2021@tux> References: <00b701cb38c0$d64fc760$82ef5620$@com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <00b701cb38c0$d64fc760$82ef5620$@com> X-OS: Debian/GNU Linux - weil ich es mir Wert bin! X-GPG-Fingerprint: EE16 3C01 7B9C 10F7 2C8B 3B86 4DB3 D9EE 7F45 84DA X-Message-Flag: "Windows" is not the answer. "Windows" is the question and the answer is "no"! X-Lugdd: Gerd Kube X-Info: My name is root. Just root. And I am licensed to kill -9 User-Agent: Mutt/1.5.18 (2008-05-17) X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0.8 tagged_above=-5 required=5 tests=BAYES_50=0.8 X-Spam-Level: X-Archive-Number: 201008/47 X-Sequence-Number: 34487 Edward W. Rouse wrote: > Is there any way to remove a duplicate row from a table? Not my db but I have > to work with it. On version 7.4 right now. > How to select the right records? You can try to use the ctid-column, see my simple example: test=# select * from dups ; i --- 1 1 1 2 2 3 4 (7 Zeilen) Zeit: 0,145 ms test=*# delete from dups where (ctid, i) not in (select max(ctid), i from dups group by i); DELETE 3 Zeit: 0,378 ms test=*# select * from dups ; i --- 1 2 3 4 (4 Zeilen) Andreas -- Really, I'm not out to destroy Microsoft. That will just be a completely unintentional side effect. (Linus Torvalds) "If I was god, I would recompile penguin with --enable-fly." (unknown) Kaufbach, Saxony, Germany, Europe. N 51.05082°, E 13.56889°