メインコンテンツまでスキップ

SET PATH

Applies to: check marked yes Databricks SQL check marked yes Databricks Runtime 19 and above

The path is the ordered list of schemas that Databricks searches when a query or DML statement references a table, view, or function without a catalog and schema qualifier. The unqualified subject of a DDL statement is current_catalog.current_schema, not a path lookup, so CREATE TABLE t creates t in the current schema. For how the path applies to queries in DDL statements and to persistent views, see Table and view resolution. For routine bodies, see Function and procedure resolution.

Syntax​

SET PATH = path_element [, ...]

path_element
{ DEFAULT_PATH |
SYSTEM_PATH |
CURRENT_SCHEMA |
PATH |
schema_name }

Parameters​

  • DEFAULT_PATH

    A keyword that expands to the PATH configuration parameter, which is the workspace default that new sessions inherit. If the parameter has not been overridden, the expansion is system.session, system.builtin, system.ai, CURRENT_SCHEMA.

  • SYSTEM_PATH

    A keyword that expands to the system-provided schemas: system.builtin, system.ai.

  • CURRENT_SCHEMA

    A virtual schema reference that resolves at use time to the current catalog and current schema (current_catalog().current_schema()). The expansion follows changes made by USE CATALOG and USE SCHEMA during the session.

  • PATH

    A keyword that expands to the current session path. Use it to extend the path without restating its contents.

  • schema_name

    A two-part name (catalog.schema) is required. Names with more than two parts are allowed. A single-part name raises INVALID_SQL_PATH_SCHEMA_REFERENCE.

    The catalog and schema do not need to exist at the time you run SET PATH. Name resolution skips missing entries and continues with the next path element.

Description​

The following rules govern which path elements SET PATH accepts and how the resulting path affects name resolution.

  • Duplicates: Duplicate path elements are not allowed. After keyword expansion, duplicates raise DUPLICATE_SQL_PATH_ENTRY.
  • System schemas: system.builtin and system.ai hold built-in scalar, table, and AI functions. system.session holds session-scoped objects such as temporary variables, temporary functions, and temporary views. Leaving system.builtin off the path is generally not advised.
  • Omitted schemas: Unqualified names resolve only against schemas on the path. If you omit CURRENT_SCHEMA, qualify persistent objects in the current schema. If you omit system.builtin or system.ai, qualify those functions, for example system.builtin.abs. If you omit system.session, unqualified temporary views, temporary functions, and session variables are not found.
  • Views and routines: Persistent views, SQL user-defined functions, and SQL SECURITY DEFINER procedures capture the path at CREATE and resolve unqualified names in their bodies against that captured path, not the invoker's session path. A SQL SECURITY DEFINER procedure omits system.session from the captured path. A SQL SECURITY INVOKER procedure uses the caller's live path. See Captured path.
  • Inspecting the path: SET PATH; does not print the path. Use current_path.

Examples​

Run the following statements in order, because later statements build on the path that earlier ones set.

SQL
-- Restore the workspace default.
> SET PATH = DEFAULT_PATH;
> SELECT current_path();
system.session,system.builtin,system.ai,main.default

-- Restrict the PATH to only the system-provided schemas.
> SET PATH = SYSTEM_PATH;
> SELECT current_path();
system.builtin,system.ai

-- Append a schema to the existing PATH without restating it.
> SET PATH = PATH, libraries.pgsql;
> SELECT current_path();
system.builtin,system.ai,libraries.pgsql

-- Put the current schema ahead of the system schemas so that user-defined
-- functions shadow built-in functions of the same name.
> SET PATH = CURRENT_SCHEMA, PATH;
> SELECT current_path();
main.default,system.builtin,system.ai,libraries.pgsql

The following statements fail and do not change the path.

SQL
-- A single-part schema name is rejected.
> SET PATH = my_schema;
[INVALID_SQL_PATH_SCHEMA_REFERENCE]

-- A duplicate path element raises an error after expansion.
> SET PATH = SYSTEM_PATH, system.builtin;
[DUPLICATE_SQL_PATH_ENTRY]