Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to correctly sort unicode strings in SQLite using Python?

Is there a simple way to order rows with unicode data in SQLite?

like image 957
Georg Schölly Avatar asked May 13 '26 15:05

Georg Schölly


2 Answers

SQLite has a BYOS (Bring Your Own Sorter) policy. See the FAQ for more details. They chose not to include (by default) any Unicode-aware sorting algorithm, to keep the SQLite library svelte and easy to statically link in.

However, you can create a collator, that sorts however you please, then tell SQLite to use it. As the other poster hinted at, there are collators in the source tree that do this using ICU. However, you can also use your own, which makes sense if you're using a library like GLib that has its own Unicode-awareness.

like image 175
Matthew Flaschen Avatar answered May 16 '26 04:05

Matthew Flaschen


There is a library called ICU that can do proper unicode sorting for you; there's a good description in this other question:

How to sort text in sqlite3 with specified locale?

like image 43
Will Avatar answered May 16 '26 04:05

Will



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!