Accent insensitive queries in PostgreSQL

Posted on 2011-02-28
Last Modified: 2012-05-11
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 ?

Question by:MarcosBarroso

Expert Comment

ID: 35000255
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.

Author Comment

ID: 35010843
I mean accent insensitive (and case insensitive) search in database data, not database definition.
LVL 61

Expert Comment

ID: 35015300
you need to convert your query to lowercase and search on lowercase-converted field..
What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.


Expert Comment

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


Author Comment

ID: 35029665
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.


Accepted Solution

ute_arbeit earned 500 total points
ID: 35038554
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


Featured Post

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Migrate this SQL to postgres 4 433
Problem to login 7 342
Creating an sp procedure in PostgreSQL database 10 333
Postgres Joining 10 55
Best database to use for Maps is PostgreSQL. This is an open source database. Comes as a package with most Linux OS. For more info visit the following site: ( This requires some add-o…
Many developers have database experience, but are new to PostgreSQL. It has some truly inspiring capabilities. I have several years' experience with Microsoft's SQL Server. When I began working with MySQL, I wanted a quick-reference to MySQL (htt…
Steps to create a PostgreSQL RDS instance in the Amazon cloud. We will cover some of the default settings and show how to connect to the instance once it is up and running.
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: (…

910 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now