pg_function_is_visible()

A function for determining whether a function is visible in the current search path

pg_function_is_visible() is a system function for determining whether a function or procedure is visible in the current schema search path.

pg_function_is_visible() was added in PostgreSQL 7.3.

Usage

pg_function_is_visible ( function oid ) → boolean

The function parameter can be provided as a text value with the regproc or regprocedure OID alias containing the function's name. In this case the name should be provided as a schema-qualified value (e.g. "someschema.somefunction"), otherwise an ERROR will be raised if the function exists but is not visible in the current search path.

Change history

Examples

Example usage for pg_function_is_visible(), assuming the hstore extension has been installed into the hstore schema:

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)

An ERROR will be raised if the function does not exist, or exists but is not schema-qualified and not in the current search path:

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...

Categories

Functions and procedures, Schema (namespace), System function