• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2105
  • Last Modified:

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 ?

1 Solution
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.
MarcosBarrosoAuthor Commented:
I mean accent insensitive (and case insensitive) search in database data, not database definition.
you need to convert your query to lowercase and search on lowercase-converted field..
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

To be not case sensitive you need to use ILIKE instead of LIKE

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:  

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

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]);

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

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.

Join & Write a Comment

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now