soundex
PG 8.0+→ textConverts a name to its Soundex code — a 4-character code representing the phonetic pronunciation. Requires the fuzzystrmatch extension.
Signature
soundex ( text ) → textParameters
| Parameter | Type | Description |
|---|---|---|
| string | text | Name or word to encode |
Examples
SELECT soundex('hello');H400SELECT soundex('Anne'), soundex('Ann');A500 | A500 (same code)SELECT * FROM people WHERE soundex(last_name) = soundex('Smith');People with names sounding like SmithSELECT last_name, soundex(last_name) AS code FROM customers GROUP BY last_name, soundex(last_name) HAVING COUNT(*) > 1 ORDER BY code;Clusters of last names sharing a Soundex codeSoundex groups names by sound: 'Smith', 'Smyth', 'Smythe' all map to S530. Use `soundex(name1) = soundex(name2)` to find likely duplicates in customer databases.
SELECT a.id, b.id, a.last_name, b.last_name FROM customers a JOIN customers b ON a.id < b.id AND soundex(a.last_name) = soundex(b.last_name) AND a.first_name ILIKE b.first_name;Potential duplicate customer records