to_regcollation() 是一个系统函数,用于将排序规则的名称转换为其 OID。
to_regcollation() 在 PostgreSQL 13 中添加。
用法
to_regcollation (text) →regcollation
to_regcollation() 等同于使用 regcollation 对象标识符类型 进行转换,但如果找不到匹配的排序规则,则返回 NULL 而不是引发 ERROR。
在评估提供的排序规则名称时会考虑当前搜索路径。
排序规则名称区分大小写,如果包含大写字符,则需要用引号括起来。
变更历史
- PostgreSQL 16
- PostgreSQL 13
- 添加(提交 a2b1faa0)
示例
to_regcollation() 的基本用法示例
postgres=# SELECT to_regcollation('pg_catalog."C"')::oid;
to_regcollation
-----------------
950
(1 row)
如果指定的排序规则不存在或未找到,则返回 NULL
postgres=# SELECT to_regcollation('foo')::oid IS NULL;
?column?
----------
t
(1 row)
如果指定的排序规则在当前搜索路径中不可见,则必须进行模式限定
postgres=# SELECT to_regcollation('british_english'), to_regcollation('collations.british_english');
to_regcollation | to_regcollation
-----------------+----------------------------
| collations.british_english
(1 row)
参考资料
- PostgreSQL 文档: 系统目录信息函数
另请参阅
regcollation, pg_collation_is_visible()
