0

I have a field title of type json that contains translations for different locales. It looks like

{'en'=>'Title', 'uk'=>'Заголовок'}

I'm trying to order records by a translation

select id, slug, title->>'$.uk' as locale_title from blog_posts
order by locale_title

It works for en locale with Latin symbols but for uk (Ukrainian) locale with Cyrillic symbols I get the wrong order like і, а, б, я. For other text fields (not json) ordering works as expected а, б, і, я

Additional info

Mysql version: 5.7.25

database collation: 'utf8mb4_unicode_ci'

4

1 回答 1

1

原来数据库的排序规则和json操作符的排序规则是不一样的:

collation(title->>'$.uk') //utf8mb4_bin
collation(other_field) //utf8mb4_unicode_ci

要解决我的问题,我应该utf8mb4_unicode_ci明确设置 json 值的排序规则:

select id, slug, title->>'$.uk' as locale_title from blog_posts
order by locale_title collate utf8mb4_unicode_ci
于 2019-05-18T08:15:41.933 回答