liveBook · Manning

Search path

As explained in Just Use Postgres!

A PostgreSQL search path is an ordered list of schemas searched for unqualified database objects.

A search path is an ordered list of schemas PostgreSQL searches for unqualified objects. Its first applicable schema becomes the current schema for commands that omit a schema name. section 2.1.2

Use the search path to:

  • Inspect the active schema order with SHOW search_path; section 2.1.2
  • Switch the current schema with SET search_path TO products; section 2.1.2
  • Query products.catalog as catalog after selecting products as the search path. section 2.2

Query a product table without its schema name

SET search_path TO products; SELECT id FROM catalog; section 2.2

SHOW search_path;

   search_path
-----------------
 "$user", public
(1 row)

Inspect the default search path before changing it. section 2.1.2

SET search_path TO products;

Apply a products-focused search path for subsequent unqualified commands. section 2.1.2

How Just Use Postgres! covers it

How deep it goes
Defines implicit schema resolution and demonstrates SHOW and SET, but does not discuss precedence or session persistence.
Examples
Uses products, customers, and sales schemas plus an unqualified catalog query.
What it assumes
Assumes familiarity with PostgreSQL schemas and table queries while demonstrating the current-schema idea directly.
What you can do after
Apply it via SQL to inspect and change schema resolution for unqualified queries.
How it connects
Connects schemas with tables and SQL queries.

Also explained in

Compare how 2 books explain search path →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Just Use Postgres!. The section links point to the parts of the book it draws on.