Solved

Accent insensitive queries in PostgreSQL

Posted on 2011-02-28
6
1,606 Views
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 ?


0
Comment
Question by:MarcosBarroso
6 Comments
 
LVL 4

Expert Comment

by:ute_arbeit
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.
0
 

Author Comment

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

Expert Comment

by:gheist
ID: 35015300
you need to convert your query to lowercase and search on lowercase-converted field..
0
NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

 
LVL 4

Expert Comment

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

regards
0
 

Author Comment

by:MarcosBarroso
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:  
     JOSE
     JOSÉ

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

Marcos
0
 
LVL 4

Accepted Solution

by:
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]);
$$ 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

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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: http://www.postgresql.org/ (http://www.postgresql.org/) 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.
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

679 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