pg.ddx.io  pgsql-interfaces@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Michael Fuhr <mike@fuhr.org>
To: b t <qtboyzz@yahoo.com>
Cc: pgsql-interfaces@postgresql.org
Subject: Re: How to write UDF in C that resemble the LIKE function
Date: Sat, 12 Feb 2005 21:07:55 -0700
Message-ID: <20050213040755.GA25541@winnie.fuhr.org> (raw)
In-Reply-To: <20050213034017.95691.qmail@web61004.mail.yahoo.com>
References: <20050213034017.95691.qmail@web61004.mail.yahoo.com>

On Sat, Feb 12, 2005 at 07:40:17PM -0800, b t wrote:
>  
> I have a question, as part of the project that I have to do for school,
> we have to implement a User Define Function in C that is similar like the
> LIKE funtion in PostgreSQL. For example where a customer is searching for
> an actor whose last name sounds like "Schwarseneger" (notice the typo).
> However, the customer is not sure neither about the spelling nor the
> pronunciation. The real star name should be "Schwarzenegger".

The contrib/fuzzystrmatch module contains implementations of the
soundex, levenshtein, and metaphone algorithms.  Here's an example:

CREATE TABLE actor (
    id    serial PRIMARY KEY,
    name  text NOT NULL
);

INSERT INTO actor (name) VALUES ('Schwarzenegger');

SELECT * FROM actor WHERE soundex(name) = soundex('Schwarseneger');
 id |      name      
----+----------------
  1 | Schwarzenegger

You could create a functional index to speed up queries on large
tables:

CREATE INDEX actor_name_soundex_idx ON actor (soundex(name));

-- 
Michael Fuhr
http://www.fuhr.org/~mfuhr/



view thread (3+ messages)

Message-ID: <20050213040755.GA25541@winnie.fuhr.org>
Permalink:  ../20050213040755.GA25541@winnie.fuhr.org/
Also on:    postgresql.org/message-id/20050213040755.GA25541@winnie.fuhr.org

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-interfaces@postgresql.org
  Cc: mike@fuhr.org, qtboyzz@yahoo.com
  Subject: Re: How to write UDF in C that resemble the LIKE function
  In-Reply-To: <20050213040755.GA25541@winnie.fuhr.org>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox