我想从 R 中的数据帧在 MySQL 中插入数据。我设法使用 dbConnect 从 R 连接到 MySQL 没有问题,但是当我尝试使用 dbWriteTable 插入我的数据时,我不断收到错误unable to find an inherited method for function 'dbWriterTable' for signature '"integer", "character", "data.frame"'
.
现在,我已经尝试了这里提到的建议解决方案 How to resolve this error--dbWriteTable()但这个解决方案对我不起作用。我的原始代码是
dbWriteTable(conn, "Date", france$Date)
因为我在 MySQL 中的表被称为
Date
我在 R 中的数据框被称为 france
并且有一列Date
包含日期(此列的类型也是日期)。提出解决方案后,我的代码变为dbWriteTable(conn, "Date", data.frame(dat=france$Date), row.names=FALSE, append=TRUE)
但我遇到了同样的错误。我尝试添加
field.types=list("date")
如以下解决方案 RMySQL dbWriteTable with field.types 中所述但我得到了同样的错误。最后,我尝试使用
dbSendQuery
连同paste()
按照此处的建议手动插入我的数据 How to insert integer values with query in MySQL in R?但我又犯了同样的错误!这真让我抓狂。任何帮助将不胜感激。
最佳答案
我遇到了同样的错误,因为我提供给 dbWriteTable()
的对象不是 data.frame。
要修复它,我只需先将对象转换为 data.frame
dat <- as.data.frame(dat)
dbWriteTable(con, "mydbtable", dat)
关于mysql - 如何修复 dbWriteTable 错误 "unable to find an inherited method for function ' dbWriterTable' 以进行签名...?”,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40480273/