Re: RFC: i18n2ascii(TEXT) stored procedure

From: "scott(dot)marlowe" <scott(dot)marlowe(at)ihs(dot)com>
To: Michael A Nachbaur <mike(at)nachbaur(dot)com>
Cc: <pgsql-sql(at)postgresql(dot)org>
Subject: Re: RFC: i18n2ascii(TEXT) stored procedure
Date: 2003-09-26 14:10:59
Message-ID: Pine.LNX.4.33.0309260809350.21038-100000@css120.ihs.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

On Thu, 25 Sep 2003, Michael A Nachbaur wrote:

> I've created the following stored procedure to allow me to do
> international-insensitive text searches, e.g. a search for "Resume" would
> match the text "Résumé".
>
> I wanted to know:
>
> a) am I missing any characters that need to be converted? My first (and only
> language) is English, so I'm in the dark when that is concerned;
> b) is there a better and/or faster way of implementing this? I don't want
> searches to bog down (at least too badly) as a result of this.
>
> CREATE OR REPLACE FUNCTION i18n2ascii (TEXT) RETURNS TEXT AS '
> my ($source) = @_;
> $source =~
> tr/áàâäéèêëíìîïóòôöúùûüÁÀÂÄÉÈÊËÍÌÎÏÓÒÔÖÚÙÛÜ/aaaaeeeeiiiioooouuuuAAAAEEEEIIIIOOOOUUUU/;
> return $source;
> ' LANGUAGE 'plperl';

You could probably accomplish the same thing without using perl via the
built in function translate(). Look in the functions-string.html in the
7.3.x documentation.

Also, the regex version of substring() is quite powerful.

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Tom Lane 2003-09-26 14:24:38 Re: How to generate object DDL of the database objects
Previous Message Evgen Potemkin 2003-09-26 14:04:18 Re: Oracle 'connect by prior' now eaiser in 7.3?