Das folgende SQL Statement ermittelt alle Duplikate in einer Tabelle. Vorraussetzung hierfür ist, dass sich die Spalte mit dem Primärschlüssel an erster Stelle befindet.
SELECT
*
FROM
(
SELECT
COUNT(substr(tmp.*::text, strpos(tmp.*::text, ','))) AS duplicate_count,
substr(tmp.*::text, strpos(tmp.*::text, ',')) AS duplicate_entry
FROM
my_table AS tmp
GROUP BY duplicate_entry
)
AS subquery
WHERE duplicate_count > 1
GROUP BY duplicate_count, duplicate_entry
*
FROM
(
SELECT
COUNT(substr(tmp.*::text, strpos(tmp.*::text, ','))) AS duplicate_count,
substr(tmp.*::text, strpos(tmp.*::text, ',')) AS duplicate_entry
FROM
my_table AS tmp
GROUP BY duplicate_entry
)
AS subquery
WHERE duplicate_count > 1
GROUP BY duplicate_count, duplicate_entry