current_path function
Returns the effective SQL Path for the current session as a comma-separated string of
qualified namespace names. See SET PATH for a
description of what the path is, how to enable it, and how to change it, and
Name Resolution for how the path drives unqualified name
resolution.
Syntax
current_path()
Arguments
This function takes no arguments. The parentheses may be omitted.
Returns
A non-nullable STRING. Each path entry is written as a dotted name with backticks added only
where required by Spark’s identifier rules. Entries are separated by a single comma.
When the path contains the virtual CURRENT_SCHEMA marker, the marker is materialized as the
catalog-qualified current schema (current_catalog.current_schema) each time
current_path() is evaluated, so subsequent USE SCHEMA statements are reflected without
re-issuing SET PATH.
Examples
> SELECT current_path();
system.builtin,system.session,spark_catalog.default
-- ANSI no-parens form returns the same value.
> SELECT CURRENT_PATH;
system.builtin,system.session,spark_catalog.default
-- The output reflects the latest SET PATH.
> SET PATH = spark_catalog.default, system.builtin;
> SELECT current_path();
spark_catalog.default,system.builtin
-- CURRENT_SCHEMA on the path is re-evaluated on every call.
> SET PATH = CURRENT_SCHEMA, system.builtin;
> USE spark_catalog.finance;
> SELECT current_path();
spark_catalog.finance,system.builtin
> USE spark_catalog.default;
> SELECT current_path();
spark_catalog.default,system.builtin
-- Inside a persistent view or SQL function body, current_path() returns the invoker's path,
-- not the frozen path captured at creation time.
> SET PATH = spark_catalog.default, system.builtin;
> CREATE VIEW v_path AS SELECT current_path() AS p;
> SET PATH = spark_catalog.other, system.builtin;
> SELECT * FROM v_path;
spark_catalog.other,system.builtin