Solved

Accent insensitive queries in PostgreSQL

Posted on 2011-02-28
6
1,536 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
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.

 
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

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

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

Suggested Solutions

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.
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

773 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