| From: | Peter Eisentraut <peter_e(at)gmx(dot)net> |
|---|---|
| To: | pgsql-general(at)postgresql(dot)org |
| Cc: | "David Inglis" <david(dot)inglis(at)ideloveto(dot)com(dot)au> |
| Subject: | Re: How to idenity duplicate rows |
| Date: | 2006-03-19 22:52:07 |
| Message-ID: | 200603192352.08564.peter_e@gmx.net |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-general |
David Inglis wrote:
> Can anybody assist with this problem I have a table that has some
> duplicated rows of data, I want to place a unique constraint on the
> columns userid and procno to eliminate this problem in the future but
> how do I identify and get rid of the existing duplication.
To find them, something like
SELECT a, b, c FROM table GROUP BY a, b, c HAVING count(*) > 1;
comes to mind, where you have to list all columns of the table in place
of a, b, c.
As for deleting all but one row in a duplicated group, you're going to
have to get at them by the oid or ctid columns perhaps.
The other idea is to run CREATE TABLE newtable AS SELECT DISTINCT * FROM
oldtable;.
--
Peter Eisentraut
http://developer.postgresql.org/~petere/
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Berend Tober | 2006-03-20 02:01:42 | Re: How to idenity duplicate rows |
| Previous Message | Tom Lane | 2006-03-19 21:43:48 | Re: ambuild parameters |