pg_type_is_visible() 是一个系统函数,用于确定数据类型或 域 是否在当前模式搜索路径中可见。
pg_type_is_visible() 函数于 PostgreSQL 7.3 中添加。
用法
pg_type_is_visible ( type oid ) → boolean
可以通过包含类型名称的 regtype OID 别名,以文本值的形式提供 type 参数。在这种情况下,类型名称应以模式限定的形式提供(例如,“someschema.sometype”),否则,如果类型存在但不在当前搜索路径中可见,则会引发 ERROR。
变更历史
- PostgreSQL 7.3
- 添加于 (提交 4ab8e690)
示例
假设 hstore 扩展已安装到 hstore 模式中,pg_type_is_visible() 的示例用法。
postgres=# \dT hstore.*
List of data types
Schema | Name | Description
--------+---------+-------------
hstore | ghstore |
hstore | hstore |
(2 rows)
postgres=# SHOW search_path;
search_path
-----------------
"$user", public
(1 row)
postgres=# SELECT pg_type_is_visible('hstore.hstore'::regtype);
pg_type_is_visible
--------------------
f
(1 row)
postgres=# SET search_path TO hstore;
SET
postgres=# SELECT pg_type_is_visible('hstore.hstore'::regtype);
pg_type_is_visible
--------------------
t
(1 row)
如果类型不存在,或者类型存在但未进行模式限定且不在当前搜索路径中,则会引发 ERROR。
postgres=# SELECT pg_type_is_visible('foo'::regtype);
ERROR: type "foo" does not exist
LINE 1: SELECT pg_type_is_visible('foo'::regtype);
postgres=# SHOW search_path;
search_path
-----------------
"$user", public
(1 row)
postgres=# SELECT pg_type_is_visible('hstore'::regtype);
ERROR: type "hstore" does not exist
LINE 1: SELECT pg_type_is_visible('hstore'::regtype);
参考资料
- PostgreSQL 文档: Schema Visibility Inquiry Functions
