From: | Andreas Kretschmer <akretschmer(at)spamfence(dot)net> |
---|---|
To: | pgsql-sql(at)postgresql(dot)org |
Subject: | Re: Duplicate rows |
Date: | 2010-08-10 19:44:33 |
Message-ID: | 20100810194433.GA2021@tux |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-sql |
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°
From | Date | Subject | |
---|---|---|---|
Next Message | msi77 | 2010-08-10 19:59:46 | Re: Duplicate rows |
Previous Message | Edward W. Rouse | 2010-08-10 19:18:38 | Duplicate rows |