odbc
odbc copied to clipboard
dbWriteTable() does not respect database and schema parameters for Snowflake?
A table (df_table) exists in two Snowflake databases, dev and prod. Both dev and prod have schemas of the same name (test) which house the tables. The table is successfully dropped in the prod environment, but remains in dev. Using dbWriteTable() to recreate the table in prod results in "Error: Table <Id> database = prod, schema = test, table = df_table exists in database, and both overwrite and append are FALSE".
If the table is also dropped in dev, the code executes without error and the table is created in the prod database and correct schema.
library(DBI)
library(odbc)
connection <-
DBI::dbConnect(drv = odbc::odbc()
,UID = 'BeMe'
,PWD = rstudioapi::askForPassword("Please enter your password")
,Server = 'foo.snowflakecomputing.com'
,Driver = "SnowflakeDSIIDriver"
,authenticator = 'externalbrowser')
dbExecute(connection, "drop table if exists prod.test.df_table;") # This works and the table is dropped from prod. A table of the same name and schema still exists in the dev database
df <- data.frame(col_1 = c("Foo", "Bar", "Baz"))
dbWriteTable(connection
,name = DBI::Id(database = 'prod', schema = 'test', table = 'df_table')
,df) # This throws the error in the description above