Re: Accent insensitive search?

From: Thom Brown <thombrown(at)gmail(dot)com>
To: Sam Mason <sam(at)samason(dot)me(dot)uk>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Accent insensitive search?
Date: 2009-03-18 17:24:20
Message-ID: bddc86150903181024m65cafd45y914215cc5b066fc9@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

2009/3/18 Sam Mason <sam(at)samason(dot)me(dot)uk>

>
> If you can't find anything better in PG; the translate[1] function would
> be my best suggestion. Performance should be better than using regular
> expressions.
>
>
Yeah, that does appear to perform better. I tried the following at it
worked for me:

CREATE OR REPLACE FUNCTION unaccent_string(text) RETURNS text AS $$
DECLARE
input_string text := $1;
BEGIN

input_string := translate(input_string, 'âãäåāăąÁÂÃÄÅĀĂĄ',
'aaaaaaaaaaaaaaa');
input_string := translate(input_string, 'èééêëēĕėęěĒĔĖĘĚ',
'eeeeeeeeeeeeeee');
input_string := translate(input_string, 'ìíîïìĩīĭÌÍÎÏÌĨĪĬ',
'iiiiiiiiiiiiiiii');
input_string := translate(input_string, 'óôõöōŏőÒÓÔÕÖŌŎŐ',
'ooooooooooooooo');
input_string := translate(input_string, 'ùúûüũūŭůÙÚÛÜŨŪŬŮ',
'uuuuuuuuuuuuuuuu');

return input_string;
END;
$$ LANGUAGE plpgsql;

Regards

Thom

In response to

Browse pgsql-general by date

  From Date Subject
Next Message John R Pierce 2009-03-18 17:32:21 Re: Accent insensitive search?
Previous Message Pedro Doria Meunier 2009-03-18 17:17:18 Re: Accent insensitive search?