Skip to content

search_path (string)

The search_path determines the order in which schemas are searched when a schema object (like a table or view) is referenced by a query without a schema qualifier. Writing fully qualified object name prefixed by a schema in queries can become tedious, and changing this parameter allows you to omit them.

By default, the database searches through a few specific schemas. It starts with a schema named after the current user, followed by the public schema:

For example:

txt
show search_path;
search_path
----------------
"$user", public
(1 row)

The first element specifies that a schema with the same name as the current user is to be searched. If no such schema exists, the entry is ignored. The second element refers to the public schema that we have seen already.

The first schema in the search path that exists is the default location for creating new objects. That is the reason that by default objects are created in the public schema. When objects are referenced in any other context without schema qualification (table modification, data modification, or query commands) the search path is traversed until a matching object is found. Therefore, in the default configuration, any unqualified access again can only refer to the public schema.

To put an additional schema neilschema on the search path, run an example such as:

txt
set search_path to neilschema,sys;
SET

show search_path;
 search_path
-------------
neilschema, sys
(1 row)

See also CURRENT_SCHEMA and the PostgreSQL documentation.