pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Joel Burton <joel@joelburton.com>
To: Cédric Dufour (public) <cdufour-public@cogito-ergo-soft.com>
Cc: Pedro Igor <pedroigor@aip.com.br>
Cc: pgsql-sql@postgresql.org
Subject: Re: Accent-insensitive
Date: Fri, 6 Dec 2002 17:17:33 -0500
Message-ID: <20021206221732.GA22607@temp.joelburton.com> (raw)
In-Reply-To: <007401c29d66$b1374690$3c8addd5@cednetwork.net>
References: <002401c29d2b$a6e168a0$0b00010a@aip.com.br>
	<007401c29d66$b1374690$3c8addd5@cednetwork.net>

On Fri, Dec 06, 2002 at 09:33:10PM +0100, Cédric Dufour (public) wrote:
> Use the 'to_ascii' function to convert your string to the "no accent" ASCII
> equivalent before accomplishing your comparison
> 
> SELECT foo FROM table WHERE ( to_ascii(foo) ILIKE to_ascii('caractères
> accentués') );
> 
> This does not work with all database locale (LATIN1 is OK, but LATIN9 is
> not).
> 
> I was actually wondering if this is efficient enough or if there is any more
> efficient method to accomplish this...

I'd think that something like:

CREATE FUNCTION lower_ascii (text) RETURNS text AS '
  BEGIN
    RETURN lower(to_ascii($1));
  END
' language 'plpgsql';

CREATE INDEX table_lower_ascii ON table(lower_ascii(field));

would perform better, since we can now use this index, whereas we
couldn't do this with ILIKE to_ascii(...).

Also, not sure it's a good idea to use ILIKE simply to get
lower-case-matching. If the user string ends with '%', for instance, it
will match everything-starting-with, which is probably not what the user
meant. Better the check against lower().

There might be a better way specifically-oriented toward
de-accentuation; this is just generic PG advice.

- J.
-- 

Joel BURTON  |  joel@joelburton.com  |  joelburton.com  |  aim: wjoelburton
Independent Knowledge Management Consultant



view thread (4+ messages)  latest in thread

Message-ID: <20021206221732.GA22607@temp.joelburton.com>
Permalink:  ../20021206221732.GA22607@temp.joelburton.com/
Also on:    postgresql.org/message-id/20021206221732.GA22607@temp.joelburton.com

 · 

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-sql@postgresql.org
  Cc: joel@joelburton.com, cdufour-public@cogito-ergo-soft.com, pedroigor@aip.com.br
  Subject: Re: Accent-insensitive
  In-Reply-To: <20021206221732.GA22607@temp.joelburton.com>

* 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