Re: Searching accented words - Mailing list pgsql-general

From Alvaro Herrera
Subject Re: Searching accented words
Date
Msg-id Pine.LNX.4.44.0208040052000.29827-100000@cm-lcon1-46-187.cm.vtr.net
Whole thread Raw
In response to Searching accented words  (João Paulo Batistella <batistellabr@yahoo.com.br>)
List pgsql-general
João Paulo Batistella dijo:

> Hi!
>
> I have, in the same column, accented words and not.
> But I don´t want to worry about it.
>
> Imagine the table Person:
> CREATE TABLE PERSON (name TEXT)
>
> INSERT INTO PERSON VALUES ('José')
> INSERT INTO PERSON VALUES ('Jose')
>
> The following statement
> SELECT * FROM PERSON WHERE NAME like 'José'
> would return only the first row, because 'José' is an
> accented word.

I think you have two ways of solving this:

1.  using regular expressions with character classes where an accented
letter is found:
    SELECT * FROM PERSON WHERE name ~* '^Jos[eé]$'
    (note the anchoring to make it equivalent to the absence of % in
    LIKE)

2.  using a function to convert the accented letters in strings.  Then
use it like
    SELECT * FROM PERSON WHERE drop_accents(name) LIKE
    drop_accents('José')

--
Alvaro Herrera (<alvherre[a]atentus.com>)
"El hombre nunca sabe de lo que es capaz hasta que lo intenta" (C. Dickens)


pgsql-general by date:

Previous
From: Masaru Sugawara
Date:
Subject: Re: Serials: removing the holes? (consecutive)
Next
From: Alvaro Herrera
Date:
Subject: Re: how to get primary / unique key on table ?