Skip to content- Sources: primary
- Summary: Pettus shows that PL/pgSQL functions and string-bodied SQL functions resolve names against the caller's search_path, which is empty or pg_catalog, pg_temp for autovacuum, pg_restore, vacuumdb and, from PostgreSQL 17, maintenance commands such as ANALYZE and REINDEX, and empty for the logical replication apply worker. In his tests a CHECK constraint function that assumed the path made a table restore empty with only one error, and an inlinable SQL function in an index expression made pg_upgrade fail after --check passed. He also shows that SECURITY DEFINER functions need SET search_path ending in pg_temp, that clusters upgraded from 14 keep CREATE on public even in template1, and that a session-level SET search_path leaks between clients behind a transaction-mode PgBouncer.
- Why it matters: Any function used by an index, constraint, trigger or materialized view needs schema-qualified names, a SET search_path clause or a BEGIN ATOMIC body before the next upgrade or restore.
- Background: search_path is the PostgreSQL setting that lists the schemas searched for unqualified names. Views, defaults and index expressions are stored already resolved, but most function bodies are stored as text and resolved at call time. Since the 2018 CVE-2018-1058 fixes, PostgreSQL tools run with an empty path to stop untrusted schemas from hijacking names.