What does collation mean?

前端 未结 9 1580
执笔经年
执笔经年 2020-12-04 10:18

What does collation mean in SQL, and what does it do?

9条回答
  •  执念已碎
    2020-12-04 11:04

    Rules that tell how to compare and sort strings: letters order; whether case matters, whether diacritics matter etc.

    For instance, if you want all letters to be different (say, if you store filenames in UNIX), you use UTF8_BIN collation:

    SELECT  'A' COLLATE UTF8_BIN = 'a' COLLATE UTF8_BIN
    
    ---
    0
    

    If you want to ignore case and diacritics differences (say, for a search engine), you use UTF8_GENERAL_CI collation:

    SELECT  'A' COLLATE UTF8_GENERAL_CI = 'ä' COLLATE UTF8_GENERAL_CI
    
    ---
    1
    

    As you can see, this collation (comparison rule) considers capital A and lowecase ä the same letter, ignoring case and diacritic differences.

提交回复
热议问题