Re: Duplicate rows

From: "Edward W(dot) Rouse" <erouse(at)comsquared(dot)com>
To: <pgsql-sql(at)postgresql(dot)org>
Subject: Re: Duplicate rows
Date: 2010-08-10 21:19:35
Message-ID: 00c901cb38d1$bb9e38a0$32daa9e0$@com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Solved. Because this is a 7.4 version and we used with oids by default, I
can use the oids instead of the ctid to remove the duplicates.

Thanks.

Edward W. Rouse

-----Original Message-----
From: pgsql-sql-owner(at)postgresql(dot)org [mailto:pgsql-sql-owner(at)postgresql(dot)org]
On Behalf Of Edward W. Rouse
Sent: Tuesday, August 10, 2010 4:43 PM
To: pgsql-sql(at)postgresql(dot)org
Subject: Re: [SQL] Duplicate rows

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;
ctid | id | activated | wake_up_time

(108,22) | 316 | f |
(36,17) | 316 | f |
(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(at)postgresql(dot)org [mailto:pgsql-sql-owner(at)postgresql(dot)org]
On Behalf Of Andreas Kretschmer
Sent: Tuesday, August 10, 2010 3:45 PM
To: pgsql-sql(at)postgresql(dot)org
Subject: Re: [SQL] Duplicate rows

Edward W. Rouse <erouse(at)comsquared(dot)com> 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°

--
Sent via pgsql-sql mailing list (pgsql-sql(at)postgresql(dot)org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-sql

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Jose Ildefonso Camargo Tolosa 2010-08-11 02:51:13 Using count on a join, group by required?
Previous Message Edward W. Rouse 2010-08-10 20:42:48 Re: Duplicate rows