r - 无法用RSQLite/DBI包替换SQLite表

标签 r sqlite

我正在尝试用新表覆盖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/

相关文章:

r - 向 ggplot 添加一个点会弄乱图例

date - 特定月份的 SQLite SELECT 日期

R从列表中获取值作为向量的最快方法

r - 带有 shinyTable 和 submitButton 的可编辑表格

c# - UWP SQLite-PCL 获取查询运行速度非常慢

performance - SQLite 性能不一致

ios - 提交新应用程序时如何更新我的 Database.sqlite

android - 在 SQLite 中创建表时在数据库中添加记录

r - dplyr 0.7 函数中的 if/else 条件

r - 我可以在 R 中的 PCA 列上使用特征选择方法吗?