Re: Duplicate rows - Mailing list pgsql-sql

From Andreas Kretschmer
Subject Re: Duplicate rows
Date
Msg-id 20100810194433.GA2021@tux
Whole thread Raw
In response to Duplicate rows  ("Edward W. Rouse" <erouse@comsquared.com>)
Responses Re: Duplicate rows  ("Edward W. Rouse" <erouse@comsquared.com>)
List pgsql-sql
Edward W. Rouse <erouse@comsquared.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
---1112234
(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
---1234
(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°


pgsql-sql by date:

Previous
From: "Edward W. Rouse"
Date:
Subject: Duplicate rows
Next
From: msi77
Date:
Subject: Re: Duplicate rows