Accent insensitive queries in PostgreSQL

In some SGBD (ex: SQLServer, Firebird), it possible to inform that a database, a table or a column is accent insensitive (or case insensitive).

All queries then become automatically accent (or case) insensitive (using any standard clauses: LIKE, IN, CONTANING, =, >, <, <>, ...)

Is there a way to do this in PostgreSQL ?


MarcosBarrosoAsked:
Who is Participating?
 
ute_arbeitConnect With a Mentor Commented:
Sorry I did not understand you question correctly in the first time.

PostgrSQL does not have builtin support for diacritical search as far as I know. But you could write a function in Postgres Perl (that has the unaccent function that converts diacritial characters to ascii characters):

CREATE FUNCTION accent_insensitive(string text) RETURNS text AS $$
use Text::Unaccent;
return unac_string('UTF-8', $_[0]);
$$ LANGUAGE plperlu IMMUTABLE STRICT;

Open in new window


And then use it in your queries like this:

SELECT name FROM customers WHERE accent_insensitive( name)=accent_insensitive('JOSÉ');

Open in new window

0
 
ute_arbeitCommented:
In PostgreSQL all database, table and column names are case insensitive by default (are converted to lower case respectively). You have to quote database, table and column names if you want them to be treated case sensitive.
0
 
MarcosBarrosoAuthor Commented:
I mean accent insensitive (and case insensitive) search in database data, not database definition.
0
Cloud Class® Course: Microsoft Exchange Server

The MCTS: Microsoft Exchange Server 2010 certification validates your skills in supporting the maintenance and administration of the Exchange servers in an enterprise environment. Learn everything you need to know with this course.

 
gheistCommented:
you need to convert your query to lowercase and search on lowercase-converted field..
0
 
l4ncel0tCommented:
To be not case sensitive you need to use ILIKE instead of LIKE

regards
0
 
MarcosBarrosoAuthor Commented:
My biggest problem in PostgreSQL is with accent insensitive queries, that are easy to do in others SGBD (ex: Firebird, SQLServer).

In these SGBD, when configured to be accent insensitive, a query like :
     SELECT name FROM customers WHERE name='JOSÉ'

Could return:  
     JOSE
     JOSÉ

I am not finding any way to do this query in PostgreSQL.

Marcos
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.