Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

is possible to have accent sensitive and case insensitive utf8 collation in mysql?

How can I perform accent-sensitive but case-insensitive utf8 search in mysql? Utf8_bin is case sensitive, and utf8_general_ci is accent insensitive.

like image 692
ts. Avatar asked Sep 30 '11 09:09

ts.


People also ask

What is accent sensitive collation?

Here is the result: ...which means that comparing 'a' to 'á' in an Accent sensitive collation treats the accented and unaccented versions of letters differently.

Is MySQL select case-sensitive?

This means MySQL is case-insensitive in Windows and macOS, while it is case-sensitive in most Linux systems. However, you can change the behavior by changing collation.

Why MySQL is not case-sensitive?

Table names are stored in lowercase on disk and name comparisons are not case-sensitive. MySQL converts all table names to lowercase on storage and lookup. This behavior also applies to database names and table aliases.

Is MySQL primary key case-sensitive?

yes. ci is case insensitive.


2 Answers

If you want to differ "café" from "cafe" You may use :

Select word from table_words WHERE Hex(word) LIKE Hex("café");

This way it will return 'café'.

Otherwise if you use :

Select word from table_words WHERE Hex(word) LIKE Hex("cafe");

it will return café. I'm using the latin1_german2_ci Collation.

like image 186
Alexandre Avatar answered Oct 23 '22 05:10

Alexandre


There doesn't seem to be one because case sensitivity is tough to do in Unicode.

There is a utf8_general_cs collation but it seems to be experimental, and according to this bug report, doesn't do what it's expected to when using LIKE.

If your data consists of western umlauts only (ie. umlauts that are included in ISO-8859-1), you might be able to collate your search operation to latin1_german2_ci or create a separate search column with it (that specific collation is accent sensitive according to this page; latin1_general_ci might be as well, I don't know and can't test right now).

like image 40
Pekka Avatar answered Oct 23 '22 03:10

Pekka