R ODCB/DBI使用非默认模式写入SQL Server表
我对R ODCB/DBI使用非默认模式写入SQL Server表,r,sql-server,database,R,Sql Server,Database,我对dbWriteTable中的新模式行为感到非常兴奋,但未能使其正常工作。我正在运行DBI0.7-15和SQLServer2012。也许我只是错误地使用了Id函数 以下代码块找不到正确的方法 cs <- "driver={SQL Server}; server={localhost}; database=testSAM; trusted_connection=true;" con <- DBI::dbConnect(odbc::odbc(
dbWriteTable
中的新模式行为感到非常兴奋,但未能使其正常工作。我正在运行DBI0.7-15和SQLServer2012。也许我只是错误地使用了Id函数
以下代码块找不到正确的方法
cs <- "driver={SQL Server};
server={localhost};
database=testSAM;
trusted_connection=true;"
con <- DBI::dbConnect(odbc::odbc(), .connection_string = cs)
df <- data.frame(id=1, word_of_day = "happy")
table_id <- DBI::Id(name = "hcai_unit_tests",
schema = "dbo",
catalog = "testSAM")
# Try with Id
res <- DBI::dbWriteTable(conn = con,
name = table_id,
value = df,
append = TRUE)
# Errors with:
Error in (function (classes, fdef, mtable) :
unable to find an inherited method for function ‘dbWriteTable’ for
signature ‘"Microsoft SQL Server", "SQL", "missing"’
这里,append=TRUE
应该可以防止出现此错误
res <- odbc::dbWriteTable(conn = con,
name = DBI::dbQuoteIdentifier(con, t),
value = df,
append = TRUE)
# Errors with:
Error: <SQL> 'CREATE TABLE "testSAM"."dbo"."hcai_unit_tests" (
"id" FLOAT,
"word_of_day" varchar(255)
)
'
nanodbc/nanodbc.cpp:1587: 42S01: [Microsoft][ODBC SQL Server Driver]
[SQL Server]There is already an object named
'hcai_unit_tests' in the database.