Search Postgresql Archives

Re: Accent insensitive search

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



PFC wrote:
>> Hi. I have a few databases created with UNICODE encoding, and I would  
>> like to be able to search with accent insensitivity. There's something  
>> in Oracle (NLS_COMP, NLS_SORT) and SQL Server (don't remember) to do  
>> this, but I found nothing in PostgreSQL, just the 'to_ascii' function,  
>> which AFAIK, doesn't work with UNICODE.
> 
> 	The easiest way is to create an extra column which will hold a copy of  
> your text, with all accents removed. You can also convert it to lowercase  
> and remove apostrophes, punctuation etc. Said column is kept up to date  
> with a trigger.

Creating an extra column which holds a copy of the data is certainly not
a very good idea, as it will create unnecessary redundancy (breaking
normal forms), bloat your table, and the trigger will have a certain
performance impact.

My suggestion is to write a function that removes the accents in a string
for your language, let's call it noaccents(text).

Then you can index the column atext with

CREATE INDEX atable_atext_idx ON atable ((noaccents(atext)))

Then every query of the form

... WHERE noaccents(atext) = noaccents('SOMÉTHING')

can use the index.

Yours,
Laurenz Albe


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux