Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Query to Snowflake database isn't working because no active warehouse is selected

I'm able to successfully connect to the Snowflake database via R but I'm having trouble getting the data because no active warehouse is selected. Below is the error message:

No active warehouse selected in the current session. Select an active warehouse with the 'use warehouse' command.

Here is my code I'm using.

  con <- DBI::dbConnect(
    odbc::odbc(), 
    UID    = user, 
    PWD    = pass, 
    Server = host,
    Warehouse = 'YOUR_WAREHOUSE_NAME',
    Driver = "SnowflakeDSIIDriver",
    Role = role,
    Database = database,
    Autthenticator = "external browser"
  )

dbGetQuery(con, "SELECT * FROM MY_TABLE LIMIT 100")

I've based my connection and query from this thread on RStudio Community but I'm not having any luck. I've also tried using the 'use warehouse MY_WAREHOUSE' command in my query without any luck.

Note: I can connect successfully and query data via Python so I think this is an R specific issue.

like image 405
trevin_flick Avatar asked Feb 17 '20 15:02

trevin_flick


People also ask

How do you know if a snowflake is active in a warehouse?

To view the current warehouse for a session, call the CURRENT_WAREHOUSE context function.

When a virtual warehouse is resumed from suspended state what is the minimum amount of Snowflake credits that it will immediately consume?

Credits are billed on a per-second basis while the warehouse is running, with a 1-minute minimum each time the warehouse is resumed; however, credit consumption is reported in 60-minute (i.e. hourly) increments.

What is warehouse in Snowflake?

A warehouse provides the required resources, such as CPU, memory, and temporary storage, to perform the following operations in a Snowflake session: Executing SQL SELECT statements that require compute resources (e.g. retrieving rows from tables and views).

How to select an active Warehouse in Snowflake?

Select an active warehouse with the 'use warehouse' command. ; nested exception is net.snowflake.client.jdbc.SnowflakeSQLException: No active warehouse selected in the current session. Select an active warehouse with the 'use warehouse' command. No active warehouse selected in the current session.

How do I create a connection query in Snowflake?

In the Snowflake window that appears, enter the name of your Snowflake server in Server and the name of your Snowflake computing warehouse in Warehouse. Optionally, enter values in any advanced options that you want to use to modify the connection query, such as a text value to use as a Role name or a command timeout.

What is nested exception in Snowflake JDBC?

; nested exception is net.snowflake.client.jdbc.SnowflakeSQLException: No active warehouse selected in the current session. Select an active warehouse with the 'use warehouse' command.

How to import data from a snowflake database using native database query?

This option is only available in Power Query Desktop. For information, go to Import data from a database using native database query. This option is only available in Power Query Desktop. Once you've selected the advanced options you require, select OK in Power Query Desktop or Next in Power Query Online to connect to your Snowflake database.


Video Answer


1 Answers

I ran into this issue too. It's probably not the best answer as I'm just testing some dev code (in python), but I had to issue:

GRANT USAGE ON WAREHOUSE my_warehouse TO ROLE writer_role;

Of which the user I was using to connect to Snowflake is a member of, then I was able to write to the table.

like image 58
Coffee and Code Avatar answered Oct 18 '22 03:10

Coffee and Code