In MySQL, my database’s and my table’s collate are utf8_persian_ci. This specific collation, unlike utf8_general_ci, considers same weight for “1”,”2″,”3″,… and “۱”,”۲”,”۳”,… (the latter is Persian number format). The same weight means that in the search query both Persian and Latin formats should be returned. Although my database, table and even collation_server (I defined it in my.cnf) are utf8_persian_ci, my search query doesn’t return both Persian and Latin numbers:
Table:
--------
| col |
|--------|
| 1 |
|--------|
| ۱ |
----------
(The col type is varchar)
Query:
SELECT * FROM my_tbl tbl where tbl.col like "1"
Results:
--------
| col |
|--------|
| 1 |
|--------|
I found that the following query returns my desired results:
SELECT * FROM my_tbl tbl where tbl.col like "1" collate utf8_persian_ci
Which returns:
--------
| col |
|--------|
| 1 |
|--------|
| ۱ |
----------
My first problem is that I can’t figure out why do I have to write collate utf8_persian_ci although the default collation of MySQL server and database are utf8_persian_ci.
My second problem is that the application I’m working on is using JPA. So the queries I’m writing are JPQL which doesnt support collate utf8_persian_ci.
I need an equivalence code to collate utf8_persian_ci in JPQL or maybe I should configure MySQL to not use collate utf8_persian_ci at the end of my query and get the sepecified result.
It’s possible that whilst the default collations of the server, database and table are
utf8_persian_ci, such defaults have been overridden by the definition of the column itself.You can force the desired collation on the column; for example: