Re: how to ignore accents? - Mailing list pgsql-novice

From Michael Fuhr
Subject Re: how to ignore accents?
Date
Msg-id 20050402014113.GA9031@winnie.fuhr.org
Whole thread Raw
In response to Re: how to ignore accents?  (Ennio-Sr <nasr.laili@tin.it>)
Responses Re: how to ignore accents?  (Ennio-Sr <nasr.laili@tin.it>)
List pgsql-novice
On Fri, Apr 01, 2005 at 08:36:35PM +0200, Ennio-Sr wrote:
>
>  CREATE FUNCTION unaccent(text) RETURNS text AS '
>   BEGIN
>       RETURN translate(&parola, "\342\347\350\351\352\364\373", "aceeeou");
>                        ^^^^^^^
>   END;
>   ' LANGUAGE plpgsql IMMUTABLE STRICT;
>
> ^^^^ [I also tried with field, &field, parola, (parola), [parameter
>       "&field?"], $1, arg1 and similar]

See the PL/pgSQL documentation to get a better idea of the syntax:

http://www.postgresql.org/docs/7.4/interactive/plpgsql.html

Let's get the basic functionality working before messing with
accented characters.  Try this:

CREATE FUNCTION unaccent(text) RETURNS text AS '
BEGIN
    RETURN translate($1, ''ABC'', ''abc'');
END;
' LANGUAGE plpgsql IMMUTABLE STRICT;

CREATE TABLE parole (
    id      serial PRIMARY KEY,
    parola  text NOT NULL
);

INSERT INTO parole (parola) VALUES ('AAA');
INSERT INTO parole (parola) VALUES ('BBB');
INSERT INTO parole (parola) VALUES ('CCC');

SELECT unaccent(parola) FROM parole;
 unaccent
----------
 aaa
 bbb
 ccc
(3 rows)

When you get that working, then you can modify the translate()
strings to convert accented characters to their unaccented
equivalents.

--
Michael Fuhr
http://www.fuhr.org/~mfuhr/

pgsql-novice by date:

Previous
From: Michael Fuhr
Date:
Subject: Re: plpgsql question - simple I would have thought
Next
From: "Morgan Kita"
Date:
Subject: Major problem with custom data type