From: Andreas Kretschmer <akretschmer@spamfence.net>
To: pgsql-sql@postgresql.org
Subject: Re: Duplicate rows
Date: Tue, 10 Aug 2010 21:44:33 +0200
Message-ID: <20100810194433.GA2021@tux> (raw)
In-Reply-To: <00b701cb38c0$d64fc760$82ef5620$@com>
References: <00b701cb38c0$d64fc760$82ef5620$@com>
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
---
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°
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-sql@postgresql.org
Cc: akretschmer@spamfence.net
Subject: Re: Duplicate rows
In-Reply-To: <20100810194433.GA2021@tux>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox