8
Search Path
Determining the object’s schema
schema is explicitly defined by a qualified name (schema.name)
name without a qualifier is looked up in the schemas specified in the
search path
Search path
defined by the search_path parameter,
the real value is shown by the current_schemas function
non-existent and inaccessible schemas are excluded
objects are created in the first schema explicitly specified in the path
pg_temp and pg_catalog schemas are implicitly included first
unless they are already specified in the search_path parameter
When specifying an object, the schema it belongs to must be specified as
well, since different schemas may contain objects with the same name.
If the object name is qualified by a schema, the explicitly specified schema is
used. Otherwise, the schema is determined by the search_path
configuration parameter. A search path is a list of schemas that is scanned
sequentially from left to right, while excluding non-existent schemas and any
schemas inaccessible to the current user.
When a new object is created with an unqualified name, the first viable
schema from the search path is selected as the target schema for the object
to be stored in. During object search, two schemas are implicitly added to
the front of the search path:
●
the pg_catalog schema for access to the system catalog,
●
the pg_temp schema if the user has created any temporary objects.
The actual search path, including implicit schemas, can be obtained using
the current_schemas(true) function.
The concept of search_path is similar to the PATH variable in operating
systems.