Postgresql 中文操作指南

53.12. pg_collation #

目录 _pg_collation_描述了可用的排序规则,它们本质上是从 SQL 名称到操作系统语言环境类别的映射。有关详细信息,请参见 Section 24.2

The catalog pg_collation describes the available collations, which are essentially mappings from an SQL name to operating system locale categories. See Section 24.2 for more information.

Table 53.12. pg_collation Columns

Table 53.12. pg_collation Columns

Column Type

Description

oid oid

Row identifier

collname name

Collation name (unique per namespace and encoding)

collnamespace oid (references pg_namespace.oid)

The OID of the namespace that contains this collation

collowner oid (references pg_authid.oid)

Owner of the collation

collprovider char

Provider of the collation: d = database default, c = libc, i = icu

collisdeterministic bool

Is the collation deterministic?

collencoding int4

Encoding in which the collation is applicable, or -1 if it works for any encoding

collcollate text

LC_COLLATE for this collation object

collctype text

LC_CTYPE for this collation object

colliculocale text

ICU locale ID for this collation object

collicurules text

ICU collation rules for this collation object

collversion text

Provider-specific version of the collation. This is recorded when the collation is created and then checked when it is used, to detect changes in the collation definition that could lead to data corruption.

请注意此目录的唯一键为 (collname, collencoding, collnamespace),而不仅仅是 (collname, collnamespace)。PostgreSQL 通常忽略所有 collencoding 无论是等于当前数据库的编码还是 -1 的排序,而创建具有与 collencoding = -1 的条目相同名称的新条目的行为是不允许的。因此,即使这在目录定义中不是唯一,使用合格的 SQL 名称 (schema.name) 来标识排序也足够了。之所以如此定义目录,原因是 initdb 会在群集初始化时使用系统上所有区域设置的条目将其填入,因此它必须能够保存群集中可能使用的所有编码。

Note that the unique key on this catalog is (collname, collencoding, collnamespace) not just (collname, collnamespace). PostgreSQL generally ignores all collations that do not have collencoding equal to either the current database’s encoding or -1, and creation of new entries with the same name as an entry with collencoding = -1 is forbidden. Therefore it is sufficient to use a qualified SQL name (schema.name) to identify a collation, even though this is not unique according to the catalog definition. The reason for defining the catalog this way is that initdb fills it in at cluster initialization time with entries for all locales available on the system, so it must be able to hold entries for all encodings that might ever be used in the cluster.

template0 数据库中,创建编码与数据库编码不匹配的排序可能很有用,因为它们可以匹配从 template0 克隆的数据库编码。当前,这必须手动完成。

In the template0 database, it could be useful to create collations whose encoding does not match the database encoding, since they could match the encodings of databases later cloned from template0. This would currently have to be done manually.