pg_type_is_visible()

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

pg_type_is_visible() is a system function  for determining whether a data type or domain is visible in the current schema search path.

pg_type_is_visible() was added in PostgreSQL 7.3.

Usage

pg_type_is_visible ( type oid ) → boolean

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

Change history

Examples

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

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)

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

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);

Categories

Data type, Schema (namespace), System function