Received: from maia.hub.org (maia-2.hub.org [200.46.204.251]) by mail.postgresql.org (Postfix) with ESMTP id 423CC633285 for ; Tue, 10 Aug 2010 17:43:02 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.251]) (amavisd-maia, port 10024) with ESMTP id 25332-01 for ; Tue, 10 Aug 2010 20:42:53 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from smtp.comsquared.com (smtp.comsquared.com [209.155.237.140]) by mail.postgresql.org (Postfix) with ESMTP id 722A8633B0E for ; Tue, 10 Aug 2010 17:42:54 -0300 (ADT) Received: from mdpserv.comsquared.com (mdpserv [10.82.40.1]) by smtp.comsquared.com (Switch-3.2.7/Switch-3.2.7) with ESMTP id o7AKgmE2025771 for ; Tue, 10 Aug 2010 16:42:51 -0400 (EDT) Received: from erouse052008 (erouse052008.ntc2s.comsquared.com [10.82.60.61]) by mdpserv.comsquared.com (8.13.6+Sun/8.13.6) with ESMTP id o7AKgmHi004906 for ; Tue, 10 Aug 2010 16:42:48 -0400 (EDT) From: "Edward W. Rouse" To: References: <00b701cb38c0$d64fc760$82ef5620$@com> <20100810194433.GA2021@tux> In-Reply-To: <20100810194433.GA2021@tux> Subject: Re: Duplicate rows Date: Tue, 10 Aug 2010 16:42:48 -0400 Message-ID: <00c801cb38cc$9814b990$c83e2cb0$@com> MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable X-Mailer: Microsoft Office Outlook 12.0 Thread-Index: Acs4xIGkc6vI6oP/RBuUenqWT0CM/QAB1iVw Content-Language: en-us X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0.79 tagged_above=-5 required=5 tests=BAYES_50=0.8, T_RP_MATCHES_RCVD=-0.01 X-Spam-Level: X-Archive-Number: 201008/49 X-Sequence-Number: 34489 I am trying to test this but get an error. select ctid, * from test where id < 3000000 order by id, ctid; ERROR: could not identify an ordering operator for type tid HINT: Use an explicit ordering operator or modify the query. If I do a select I get this: select ctid, * from test where id < 3000000 order by id; =20 ctid | id | activated | wake_up_time=20 (108,22) | 316 | f | =20 (36,17) | 316 | f | =20 (used 2 rows only for brevity And when I tried max(ctid) I got: ERROR: function max(tid) does not exist HINT: No function matches the given name and argument types. You may = need to add explicit type casts. I appreciate all the help and this feels like I'm almost there. Thanks Edward W. Rouse -----Original Message----- From: pgsql-sql-owner@postgresql.org = [mailto:pgsql-sql-owner@postgresql.org] On Behalf Of Andreas Kretschmer Sent: Tuesday, August 10, 2010 3:45 PM To: pgsql-sql@postgresql.org Subject: Re: [SQL] Duplicate rows 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. >=20 How to select the right records? You can try to use the ctid-column, see my simple example: test=3D# select * from dups ; i --- 1 1 1 2 2 3 4 (7 Zeilen) Zeit: 0,145 ms test=3D*# delete from dups where (ctid, i) not in (select max(ctid), i = from dups group by i); DELETE 3 Zeit: 0,378 ms test=3D*# select * from dups ; i --- 1 2 3 4 (4 Zeilen) Andreas --=20 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=B0, E = 13.56889=B0 --=20 Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-sql