pg_import_system_collations()

用于向系统目录添加排序规则的函数

pg_import_system_collations() 是一个系统函数,用于从操作系统可用的排序规则中,将它们添加到系统目录。

pg_import_system_collations()PostgreSQL 10 中添加。

用法

pg_import_system_collations ( schema regnamespace ) → integer

pg_import_system_collations() 通常在操作系统安装了新的 locale 后使用。

提供的模式通常是 pg_catalog,但也可能是用户定义的模式。

返回新添加的排序规则对象的数量。

变更历史

示例

确定缺少一个必需的 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.

分类

排序规则, 区域设置和字符集处理, 系统函数

另请参阅

pg_collation, pg_collation_actual_version(), pg_database_collation_actual_version()

反馈

请在此处提交对“pg_import_system_collations()”的任何评论、建议或更正 here