Re: LC_CTYPE and matching accented chars

From: Alvaro Herrera <alvherre(at)commandprompt(dot)com>
To: Martin Langhoff <martin(at)catalyst(dot)net(dot)nz>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: LC_CTYPE and matching accented chars
Date: 2007-06-26 14:21:42
Message-ID: 20070626142142.GD8382@alvh.no-ip.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Martin Langhoff wrote:
> Trying to understand how I can get Pg 8.2 to match 'martín' when I
> search for 'martin', and going through the documentation, specially
>
> http://www.postgresql.org/docs/8.2/static/locale.html
> http://www.postgresql.org/docs/8.1/static/functions-matching.html
>
> Here is a transcript of my commandline - I suspect I am quite close, but
> something is missing. Hints _really_ appreciated!

> =# create table test (value text);
> CREATE TABLE
> =# insert into test values ('martín');
> INSERT 0 1
>
> # this is apparently the right way to
> # select base character based on the "equivalence class"
> # as defined in the LC_CTYPE
> =# select * from test where value ~ 'mart[=i=]n';

I think it would be much easier if you did something like

select * from test where lower(to_ascii(value)) = lower(to_ascii('martín'));

When to_ascii doesn't work (for example because it doesn't work in UTF8)
you may want to use convert() to recode the text to latin1 or latin9.

--
Alvaro Herrera http://www.CommandPrompt.com/
PostgreSQL Replication, Consulting, Custom Development, 24x7 support

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Fernando Hevia 2007-06-26 14:25:49 Re: NO DATA FOUND Exception
Previous Message Tom Lane 2007-06-26 14:04:26 Re: Rule vs Trigger