Sunday, March 15, 2009

Fuzzy String Match in PostgreSQL with Debian

If you want to use FuzzyStringMatching in PostgreSQL you have to do the following steps.
Prerequisites: Debian 4.0 Etch (or higher), installed PostgreSQL 8.3, existing database in postgres

1. Install the postgresql-contrib package via apt

apt-get install postgresql-contrib

2. Switch to your postgres user

su - postgres

3. Open the psql interactive terminal with the following options database, user, password and the installation file for the fuzzy string functions

psql -d myDatabase -U myUser --password myPassword -h localhost -f /usr/share/postgresql/8.3/contrib/fuzzystrmatch.sql

Afterwards you can use the soundex, levenshtein, metaphone and double metaphone functions in your sql statements.
Offical documentation about the fuzzy string match functions: http://www.postgresql.org/docs/8.3/static/fuzzystrmatch.html