X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.130]) by svr1.postgresql.org (Postfix) with ESMTP id BC935D1B4FC for ; Fri, 26 Sep 2003 14:16:40 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (neptune.hub.org [64.117.224.130]) (amavisd-new, port 10024) with ESMTP id 23257-04 for ; Fri, 26 Sep 2003 11:16:31 -0300 (ADT) Received: from mail1.ihs.com (mail1.ihs.com [170.207.70.222]) by svr1.postgresql.org (Postfix) with ESMTP id AD7B9D1B4E1 for ; Fri, 26 Sep 2003 11:16:26 -0300 (ADT) Received: from css120.ihs.com (css120.ihs.com [170.207.105.120]) by mail1.ihs.com (8.12.10/8.12.10) with ESMTP id h8QEG51o005075; Fri, 26 Sep 2003 08:16:06 -0600 (MDT) Date: Fri, 26 Sep 2003 08:10:59 -0600 (MDT) From: "scott.marlowe" To: Michael A Nachbaur Cc: Subject: Re: RFC: i18n2ascii(TEXT) stored procedure In-Reply-To: <200309251650.53855.mike@nachbaur.com> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=ISO-8859-1 Content-Transfer-Encoding: 8BIT X-IHS-MailScanner: Found to be clean X-IHS-MailScanner-SpamCheck: X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200309/328 X-Sequence-Number: 15306 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.