Ukrainian letters are poorly sorted

221 Views Asked by At

The problem is that when using order_by(), Ukrainian letters are incorrectly sorted alphabetically, that is, before "а", "б" is placed "і" and "є".

2

There are 2 best solutions below

0
Patrick Bond On

Changing the column encoding to utf8mb4_unicode_ci helped me. PS. Failed to change the encoding of the entire database or table. Only the column.

But later it turned out that this was not enough for me. I need to sort addresses that contain letters and numbers. In the end I was able to do it the way I needed with Natsort

from natsort import humansorted
import locale

locale.setlocale(locale.LC_ALL, 'uk_UA.UTF-8')
objects = humansorted(objec, key=lambda p: p.address)
0
Bill Karwin On

You can change the collation of all columns of a table this way:

ALTER TABLE <mytable> CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

There's no statement to change all tables in one operation. You have to do it one table at a time.