gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-03 18:16:03 26 4
gpt4 key购买 nike

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

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com