bounty还有6天到期。回答此问题可获得+50声望奖励。user16024709希望引起更多关注此问题。
我在尝试将表写入Snowflake数据库时遇到了一个奇怪的问题。我无法创建与另一个模式中的表同名的表。
library(DBI)
df <- data.frame(col1 = rnorm(5), col2 = rnorm(5))
con1 <- DBI::dbConnect(odbc::odbc(), Server = server,
port = 443, Driver = "SnowflakeDSIIDriver", database = "db",
Warehouse = "warehouse", role = "role", schema = "schema1",
authenticator = "oauth", token = token)
# This creates the table named TEMP with 5 rows
DBI::dbWriteTable(conn = con1, 'TEMP', value = df, append = TRUE) #works
# Repeat the same thing to append 5 more rows
DBI::dbWriteTable(conn = con1, 'TEMP', value = df, append = TRUE) #works
# Now let's change the schema
con1 <- DBI::dbConnect(odbc::odbc(), Server = server,
port = 443, Driver = "SnowflakeDSIIDriver", database = "db",
Warehouse = "warehouse", role = "role", schema = "schema2",
authenticator = "oauth", token = token)
# Try to write it to TEMP table in schema2
DBI::dbWriteTable(conn = con1, 'TEMP', value = df, append = TRUE) #error
new_result(connection@ptr,statement,immediate)出错:nanodbc/nanodbc.cpp:1412:42 S 02:SQL编译错误:表“TEMP”不存在或未授权。
# Change the table name to TEMP1
DBI::dbWriteTable(conn = con1, 'TEMP1', value = df, append = TRUE) #works
我已经尝试搜索了很多,但所有的东西都把我引向了写入非默认模式的问题。
Issue Writing to Non-Default Schema when Table Does Not Have "_" In Name
https://github.com/r-dbi/DBI/issues/181
https://github.com/r-dbi/odbc/issues/197
他们建议的解决方案是使用Id
函数来区分模式和表。我试过了,但还是得到了同样的错误。
table_id <- Id(schema="schema2", table="TEMP")
DBI::dbWriteTable(conn = con1, table_id, value = df, append = TRUE)
new_result(connection@ptr,statement,immediate)出错:nanodbc/nanodbc.cpp:1412:42 S 02:SQL编译错误:表“db.schema2.TEMP”不存在或未授权。
有什么建议吗?
1条答案
按热度按时间vsdwdz231#
看起来你可能需要在重新创建
con1
之前使用dbDisconnect()
。你可以通过检查con1的内容来仔细检查con1是否正确更改。它应该包含一个要检查的路径。