catalog-pg-collation.md 4.1 KB
Newer Older
K
KyleZhang 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
## 52.12. `pg_collation`

[]()

 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](collation.html) for more information.

**Table 52.12. `pg_collation` Columns**

|                                                                                                      Column Type<br/><br/> Description                                                                                                      |
|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|                                                                                                    `oid` `oid`<br/><br/> Row identifier                                                                                                     |
|                                                                               `collname` `name`<br/><br/> Collation name (unique per namespace and encoding)                                                                                |
|                                            `collnamespace` `oid` (references [`pg_namespace`](catalog-pg-namespace.html).`oid`)<br/><br/> The OID of the namespace that contains this collation                                             |
|                                                                 `collowner` `oid` (references [`pg_authid`](catalog-pg-authid.html).`oid`)<br/><br/> Owner of the collation                                                                 |
|                                                                  `collprovider` `char`<br/><br/> Provider of the collation: `d` = database default, `c` = libc, `i` = icu                                                                   |
|                                                                                   `collisdeterministic` `bool`<br/><br/> Is the collation deterministic?                                                                                    |
|                                                              `collencoding` `int4`<br/><br/> Encoding in which the collation is applicable, or -1 if it works for any encoding                                                              |
|                                                                                    `collcollate` `name`<br/><br/>`LC_COLLATE` for this collation object                                                                                     |
|                                                                                      `collctype` `name`<br/><br/>`LC_CTYPE` for this collation object                                                                                       |
|`collversion` `text`<br/><br/> 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.|

 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.

 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.