Re: How to find not unique rows in a table?

From: "A(dot) Kretschmer" <andreas(dot)kretschmer(at)schollglas(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: How to find not unique rows in a table?
Date: 2008-10-08 11:36:37
Message-ID: 20081008113636.GJ12115@a-kretschmer.de
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

am Wed, dem 08.10.2008, um 13:20:47 +0200 mailte A B folgendes:
> Assuming you have a table where some rows have the same values in all
> columnes, how do you find these rows?

You can use the ctid-column:

test=*# select * from dup;
a | b
---+---
1 | 1
1 | 2
2 | 1
1 | 1
3 | 3
3 | 3
(6 rows)

test=*# select * from dup where (ctid,a,b) not in (select distinct on (a,b) ctid,* from dup);
a | b
---+---
1 | 1
3 | 3
(2 rows)

Andreas
--
Andreas Kretschmer
Kontakt: Heynitz: 035242/47150, D1: 0160/7141639 (mehr: -> Header)
GnuPG-ID: 0x3FFF606C, privat 0x7F4584DA http://wwwkeys.de.pgp.net

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message hubert depesz lubaczewski 2008-10-08 12:15:46 Re: How to find not unique rows in a table?
Previous Message admin 2008-10-08 11:27:19 8.4 RPMs