19 Oct 18 · Mike-Barn ·       Add to Favorites  

How to switch to a Warehouse, Database, Schema using SQL query in Snowflake

The first step in Snowflake is to choose your Virtual Warehouse, Correct Database and schema. Once you have done that you can start executing your favorite queries. The warehouse must be running before queries and other DML statements can be executed in the session (If you have given AUTO_RESUME=TRUE, it will start automatically once you fire the query)

Example

USE WAREHOUSE MARKETING_TEAM_WH;
USE DATABASE SALES_WH_DB;
USE SCHEMA POWER_USER_VIEWS;

You can also verify if you are in the correct schema, using the below command:

select current_warehouse(), current_database(), current_schema();

Output:

+---------------------+--------------------+------------------+
| CURRENT_WAREHOUSE() | CURRENT_DATABASE() | CURRENT_SCHEMA() |
|---------------------+--------------------+------------------|
| MARKETING_TEAM_WH | SALES_WH_DB | POWER_USER_VIEWS |
+---------------------+--------------------+------------------+

Related Error:

Cannot perform SELECT. This session does not have a current database. Call 'USE DATABASE', or use a qualified name.

If you see this error, you will have to choose the correct database name as mentioned in this article.


Mike-Barn

posted on 19 Oct 18

Enjoy great content like this and a lot more !

Signup for a free account to write a post / comment / upvote posts. Its simple and takes less than 5 seconds

Copied