pg_function_is_visible() 是一个系统函数,用于确定函数或过程在当前模式搜索路径中是否可见。
pg_function_is_visible() 在 PostgreSQL 7.3 中添加。
用法
pg_function_is_visible (functionoid) →boolean
可以使用 regproc 或 regprocedure OID 别名包含函数名称的文本值来提供 function 参数。在这种情况下,名称应提供为模式限定值(例如,“someschema.somefunction”),否则如果函数存在但不在当前搜索路径中可见,将引发 ERROR。
变更历史
- PostgreSQL 7.3
- 添加于 (提交 4ab8e690)
示例
假设 hstore 扩展已安装到 hstore 模式中,pg_function_is_visible() 的示例用法
postgres=# CREATE EXTENSION hstore WITH SCHEMA hstore ; CREATE EXTENSION postgres=# SHOW search_path; search_path ----------------- "$user", public (1 row) postgres=# SELECT hstore(ROW(1,2)); ERROR: function hstore(record) does not exist LINE 1: SELECT hstore(ROW(1,2)); ^ HINT: No function matches the given name and argument types. You might need to add explicit type casts. postgres=# SELECT hstore.hstore(ROW(1,2)); hstore ---------------------- "f1"=>"1", "f2"=>"2" (1 row) postgres=# SELECT pg_function_is_visible('hstore.hstore(record)'::regprocedure); pg_function_is_visible ------------------------ f (1 row) postgres=# SET search_path TO public,hstore; SET postgres=# SELECT pg_function_is_visible('hstore.hstore(record)'::regprocedure); pg_function_is_visible ------------------------ t (1 row)
如果函数不存在,或者函数存在但未进行模式限定且不在当前搜索路径中,则会引发 ERROR。
postgres=# SELECT pg_function_is_visible('foo'::regproc);
ERROR: function "foo" does not exist
LINE 1: SELECT pg_function_is_visible('foo'::regproc);
postgres=# SHOW search_path;
search_path
-----------------
"$user", public
(1 row)
postgres=# SELECT pg_function_is_visible('hstore(record)'::regprocedure);
ERROR: function "hstore(record)" does not exist
LINE 1: SELECT pg_function_is_visible('hstore(record)'::regprocedure...
参考资料
- PostgreSQL 文档: 模式可见性查询函数,
