current_schemas()

A function listing the schemas in the current search path

current_schemas() is a system function listing the schemas in the current effective search path.

current_schemas() was added in PostgreSQL 7.3.

Usage

current_schemas ( include_implicit boolean ) → name[]

If include_implicit is FALSE, all schemas defined in the current search path which exist and are searchable are returned.

If include_implicit is TRUE, the returned list includes implicitly searched system schemas such as pg_catalog.

Change history

Examples

Basic usage example of :

postgres=# SELECT * FROM current_schemas(false);
 current_schemas 
-----------------
 {public}
(1 row)

Including implicit schemas:

postgres=# SELECT * FROM current_schemas(true);
   current_schemas   
---------------------
 {pg_catalog,public}
(1 row)

Schemas are listed in the order defined in search_path:

postgres=# CREATE SCHEMA foo;
CREATE SCHEMA

postgres=# CREATE SCHEMA bar;
CREATE SCHEMA

postgres=# SET search_path TO bar, foo;
SET

postgres=# SELECT * FROM current_schemas(false);
 current_schemas 
-----------------
 {bar,foo}
(1 row)

Non-existent schemas will not be listed:

postgres=# SET search_path TO baz, boo;
SET

postgres=# SELECT * FROM current_schemas(false);
 current_schemas 
-----------------
 {}
(1 row)

Categories

Schema (namespace), System function

See also

current_schema()