我正在尝试用新表覆盖SQLite数据库中的表,但收到以下错误消息,我不理解,到目前为止,我无法在线找到答案:
RS-DBI driver: (error in statement: duplicate column name: row_names)
下面,我创建了一些简化的示例代码来复制我的问题:
library(RSQLite) # will load DBI as well
## open a connection to a SQLite database
con <- dbConnect(dbDriver("SQLite"), dbname = "testDB.db")
# save internal R dataset in database as table
dbWriteTable(con, "mtcarsTab", mtcars, overwrite = T)
# subset database table and store as data frame
subDf <- dbGetQuery(con, "SELECT * FROM mtcarsTab WHERE cyl = 4")
# try to replace old table with new table
dbWriteTable(con, "mtcarsTab", subDf, overwrite = T)
最后一条语句的结果输出为:
> dbWriteTable(con, "mtcarsTab", subDf, overwrite = T)
[1] FALSE
Warning message:
In value[[3L]](cond) :
RS-DBI driver: (error in statement: duplicate column name: row_names)
最佳答案
从注释转移:将row.names=FALSE
添加到dbWriteTable
调用
关于r - 无法用RSQLite/DBI包替换SQLite表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21833101/