我有一个数据框,称为df
,看起来像这样:
dte, val
2012-01-01, 23.2323
2012-01-02, 34.343
列上的类型是日期和数字。我想使用已经打开的连接将其写入 MySQL 数据库。连接工作正常,因为我可以很好地查询数据库。我尝试运行以下命令:
dbWriteTable(con, name="table_name", value=df, field.types=list("date", "double(20,10)"))
这会产生错误:
函数(类、fdef、mtable)中的错误:无法找到函数“make.db.names”的继承方法,签名“MySQLConnection”,“NULL”
如果我不指定 field.types,然后运行:
dbWriteTable(con, name="table_name", value=df)
我收到错误:
mysqlExecStatement(conn, statements, ...) 中的错误:RS-DBI 驱动程序:(无法运行语句:在没有密钥长度的密钥规范中使用 BLOB/TEXT 列“dte”)
有人能解释一下吗?
Thanks
After playing with things, I realized what the problem is: field.types
must be a NAMED list vector, not simply a list; additionally the row names must not be included otherwise we need three field types. For the above example, the following works fine:
dbWriteTable(con, name="table_name", value=df,
field.types = c(dte="date", val="double(20,10)"), row.names=FALSE)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)