pg_import_system_collations() 是一个系统函数,用于从操作系统可用的排序规则中,将它们添加到系统目录。
pg_import_system_collations() 在 PostgreSQL 10 中添加。
用法
pg_import_system_collations (schemaregnamespace) →integer
pg_import_system_collations() 通常在操作系统安装了新的 locale 后使用。
提供的模式通常是 pg_catalog,但也可能是用户定义的模式。
返回新添加的排序规则对象的数量。
变更历史
- PostgreSQL 16
- 增加了 Windows 支持(提交 bf03cfd1)
- PostgreSQL 10
- 添加(提交 aa17c06f)
示例
确定缺少一个必需的 locale
postgres=# CREATE TABLE foo (id INT NOT NULL, val TEXT COLLATE "de_DE.utf8"); ERROR: collation "de_DE.utf8" for encoding "UTF8" does not exist
安装缺失的 locale(此处为基于 Debian 的系统)
# apt-get install -y language-pack-de ... Generating locales (this might take a while)... de_AT.UTF-8... done de_BE.UTF-8... done de_CH.UTF-8... done de_DE.UTF-8... done de_IT.UTF-8... done de_LI.UTF-8... done de_LU.UTF-8... done Generation complete.
执行 pg_import_system_collations()
postgres=# SELECT pg_import_system_collations('pg_catalog');
pg_import_system_collations
-----------------------------
14
(1 row)
现在可以创建具有所需排序规则的表了
postgres=# CREATE TABLE foo (id INT NOT NULL, val TEXT COLLATE "de_DE.utf8"); CREATE TABLE
如果没有可导入的新排序规则,将返回 0
postgres=# SELECT pg_import_system_collations('pg_catalog');
pg_import_system_collations
-----------------------------
0
(1 row)
目标模式必须始终显式指定
postgres=# SELECT pg_import_system_collations();
ERROR: function pg_import_system_collations() does not exist
LINE 1: SELECT pg_import_system_collations();
^
HINT: No function matches the given name and argument types. You might need to add explicit type casts.
参考资料
- PostgreSQL 文档: 排序规则管理函数
