Categories:

Context Functions (Session Object)

CURRENT_SCHEMA

Returns the name of the schema in use by the current session.

To specify a different schema for the session, execute the USE SCHEMA command.

Syntax

CURRENT_SCHEMA()
Copy

Arguments

None.

Usage notes

  • Do not confuse this function with the similarly named function CURRENT_SCHEMAS.

  • If you call this function in the body of a masking or row access policy, in the handler code of a UDF, or in the definition of a view, the function returns the following:

    • In a policy, the function returns the database or schema that contains the table or view that is protected by the policy.

    • In a UDF, the function returns the database or schema that contains the UDF.

    • In a view, the function returns the database or schema that contains the view.

Examples

Show the current warehouse, database, and schema:

SELECT CURRENT_WAREHOUSE(), CURRENT_DATABASE(), CURRENT_SCHEMA();
Copy

Output:

+---------------------+--------------------+------------------+
| CURRENT_WAREHOUSE() | CURRENT_DATABASE() | CURRENT_SCHEMA() |
|---------------------+--------------------+------------------|
| DEV_WAREHOUSE       | TEST_DATABASE      | UDF_TEST_SCHEMA  |
+---------------------+--------------------+------------------+
Copy