mysql - 如何修复 dbWriteTable 错误 "unable to find an inherited method for function ' dbWriterTable' 以进行签名...?”

标签 mysql r database dbconnection

我想从 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/

相关文章:

php - 我想要一个可打印的网页,其中包含数据库中的类(class),我怎样才能使其美观?

mysql - 错误代码 : 1137 Can't reopen table: 'amountforagents'

arrays - 将向量转换为 3 维矩阵

javascript - 出于某种原因,无法使用 Reactjs 中的 axios 从 api 获取数据以在屏幕上呈现

sql - 使用 pgadmin3 的 Postgresql 导入转储

android - 如何使用推送通知同步 SQLite 和 MySQL 数据库?

regex - 在 R 中提取特定文本后面的数字

r - 在 R 中获得治疗和控制的所有组合

mysql - 如何修复 "No suitable driver found for jdbc:mysql://localhost:3306/emp"?

MySQL Partitioning/Sharding/Splitting - 走哪条路?