What does COLLATE LOCALIZED ASC stand for?

孤街浪徒 提交于 2019-12-03 09:27:37

Collate is just fancy speak for sort (well sort of). So this is sort ordering based on localized preferences (i.e. current language's alphabet and conventions) in ascending order.

It instructs SQLite to sort non-ASCII characters appropriately. Chars with diacritics (some call them accents) have higher byte codes than the character Z, so a plain ASCII sort wouldn't fit to many foreign languages.

For example, the capital A char's byte code is 0x41 and the capital Z char's is 0x5A. Then we have the Á (capital A accute) which code in Unicode is 0x00C1. So a plain byte code sort would result the Á to be after the Z.

But in languages that have this kind of characters the convention is to put those with diacritics as if they didn't have the diacritic. So the Á should be together with the plain A, at least before B.

And to illustrate, we have below a list of names sorted using their bytecode:

  • Brenda
  • Debby
  • George
  • Álvaro
  • Érico

Now using the COLLATE LOCALIZED it would sort by the "base" of the character:

  • Álvaro
  • Brenda
  • Debby
  • Érico
  • George

COLLATE is an SQL operator that lets you override the default sort order for strings. For example, "COLLATE NOCASE" does case-insensitive comparison, and "COLLATE BINARY" does a case-sensitive comparison.

The SQLite C interface lets you define custom collations (http://www.sqlite.org/c3ref/create_collation.html).

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!