排序规则的确切含义 'de-DE-u-kn-true'

What exactly means the collation 'de-DE-u-kn-true'

为了使用数值对 PostgreSQL 14 varchar 列进行排序,我使用了

创建的排序规则
CREATE COLLATION de_pos (LOCALE = 'de-DE-u-kn-true', PROVIDER = 'icu');`

使用这样的排序规则 ORDER BY 会产生像这样的正确顺序
1.2.10
1.2.20
1.2.100

如果没有特殊排序规则,ORDER BY 会导致
1.2.10
1.2.100
1.2.20

我想知道排序规则定义的每个部分到底是什么意思?

de-DE => 德意志语言环境
u => UTF8 ????
kn => ????
真 => ????

参见ICU Collations in the PostgreSQL documentation. This links to the ICU documentation, which - with some indirection - leads to Unicode Locale Identifier, which makes clear that the -u introduces the Unicode Locale Extensions, and kn is one of those extensions. When you look at Collation Settings,您会发现kn配置了数字排序。 true 是该选项的配置(意思是,数字排序开启):

If set to on, any sequence of Decimal Digits (General_Category = Nd in the [UAX44]) is sorted at a primary level with its numeric value. For example, "A-21" < "A-123". The computed primary weights are all at the start of the digit reordering group. Thus with an untailored UCA table, "a$" < "a0" < "a2" < "a12" < "a⓪" < "aa".

这有时称为“自然排序顺序”。

换句话说,de-DE-u-kn-true是:

  • de:语言德语
  • DE:德国地区
  • u: 以下是 Unicode Locale Extension
  • kn:Unicode 区域设置扩展数字排序
  • truekn 的值,表示数字排序开启

您可以通过指定属性名称来自定义排序规则的排序行为。 在这种情况下,kn-true 代表自然排序顺序或数字排序顺序,根据数值对数字进行排序。