Categories:

Context functions (Session Object)

CURRENT_DATABASE

Returns the name of the database in use for the current session.

To specify a different database for the session, execute the USE DATABASE command.

Syntax

CURRENT_DATABASE()
Copy

Arguments

None.

Usage notes

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