Categories:

Context functions (Session Object)

CURRENT_DATABASE¶

Returns the name of the current database, which varies depending on where you call the function:

  • If you call this function outside of a policy, UDF, or view, it returns the database that is in use for the current session.

  • If you call this function in the body of a policy, for example a masking policy, it returns the database that contains the table or view that is protected by the policy.

  • If you call this function in the handler code of a UDF, it returns the database that contains the UDF.

  • If you call this function in the definition of a view, it returns the database that contains the view.

Syntax¶

CURRENT_DATABASE()
Copy

Arguments¶

None.

Usage notes¶

None.

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