Query
SELECT COUNT(*), name, number
FROM tbl
GROUP BY name, number
HAVING COUNT(*) > 1
It sometimes fails to find duplicates between lower case and upper case.
E.g.: sunny and Sunny don’t show up as a duplicates.
So how to find all possible duplicates in PostgreSQL for two columns.
lower()/upper()Use one of these to fold characters to either lower or upper case. Special characters are not affected:
unaccent()If you actually want to ignore diacritic signs, like your comments imply, install the additional module
unaccent, which provides a text search dictionary that removes accents and also the general purpose functionunaccent():Makes it very simple:
Result:
This doesn’t strip non-letters. Add
regexp_replace()like @Craig mentioned for that:Result:
You can even build a functional index on top of that: