Query Data from Snowflake Database

I am totally a newbie in RStudio. I am trying to query some data from a table in Snowflake database. I was able to create the connection successfully.

When I tried to run a query I am getting this error. I googled for an answer but I cannot find one.

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

Hi! Welcome!

I think it might be hard for people to help with this problem without some more information. Error messages are often difficult to interpret without seeing them in the context of the code that produced them. It will help a lot if you can at least post the exact code that you ran (including your library() calls) which resulted in the error message.

Even better...

People here often ask posters to go one step further, and create a self-contained reproducible example using the tools in the reprex package. It's difficult to make database connection problems truly self-contained, but any effort you can make in that direction would be very helpful. A major benefit of the reprex package is that it produces a formatted chunk of both the code and any output, including error messages, all ready for posting, which makes it really easy for others to understand what's going on.

You also might want to take a look at this guide: FAQ: Tips for writing R-related questions

In Snowflake, before you can submit a query you need to use a "warehouse" which is the actual engine that runs those queries.

Right after the connection is created you need to explicitly ask for any of your available warehouse:

  con <- DBI::dbConnect(
    drv    = odbc::odbc(), 
    UID    = user, 
    PWD    = pass, 
    Server = host,
    Driver = "SnowflakeDSIIDriver"
  )
  DBI::dbSendQuery(con, 'use warehouse YOUR_WAREHOUSE_NAME')

Another alternative (the one I use) is to set the warehouse parameter in the connection call:

  con <- DBI::dbConnect(
    drv    = odbc::odbc(), 
    UID    = user, 
    PWD    = pass, 
    Server = host,
    Warehouse = 'YOUR_WAREHOUSE_NAME',
    Driver = "SnowflakeDSIIDriver"
  )
1 Like