8
Search Path
Determining the object’s schema
a qualified name (schema.name) explicitly defines the schema
an unqualified name is looked up in schemas listed in search path
Search path
is defined by the search_path parameter,
the actual path is displayed by the current_schemas function
excludes non-existent and inaccessible schemas
pg_temp and pg_catalog schemas are implicitly included first
unless they are already specified in the search_path parameter
the first explicitly specified schema is used for object creation
Different schemas can contain objects with the same name, so when
specifying an object, it’s necessary to identify its schema.
If the object has a qualified name, it’s easy: the explicitly specified schema
is used. Otherwise, PostgreSQL tries to find the object name in one of the
schemas listed in the search path, which is defined in the search_path
configuration parameter.
The actual search path can differ from the search_path parameter value.
It excludes non-existent schemas listed in search_path as well as those
schemas that the current user cannot access (we will cover access control
in one of the next lectures of this course). Besides, the following schemas
are implicitly added to the beginning of the search path:
●
the pg_catalog schema to ensure that the system catalog is always
accessible
●
the pg_temp schema if the user has created temporary objects
You can view the actual search path, including the implicitly added schemas,
by calling the current_schemas(true) function. Schemas are looked up
as they follow in the search path, from left to right. If the object with the
specified name is not found in the schema, the search continues in the next
one.
If you create an object with an unqualified name, it will get into the first
schema that is explicitly specified in the search path.
We can say that search_path is somewhat analogous to the PATH variable
in operating systems.