dbplyr copy_to not saving table to database

你。 提交于 2020-02-02 15:05:40

问题


I am trying to copy a local dataframe from R to my db2 database. I have permissions to write to the table and I have verified the connection is working.

I am using:

copy_to(connection, data.frame, name = my_table_name)

I am getting the following error and it doesnt make sense to me. The object it says does not exist is the very object I am trying to create. What am I doing wrong?

Error in typeof(x) : object 'my_table_name' not found


回答1:


by default, copy_to() tries to create a temporary table. An option is to add the argument temporary = FALSE, to overcome the TEMPORARY token error. A better solution is for the package that you are using to connect, which is hopefully the odbc package, is for it to add support for DB2 databases. In other words, odbc will need to know what is the specific command needed to properly create a temporary table. Once that's fixed, copy_to() will work. If it's indeed the odbc package that you are using, I would recommend that you open a GitHub issue in the package's repo.




回答2:


This might be caused by an issue with DBI not dbplyr. See here. There is a work around that draws on the DBI package. you can more details on it here.

In summary: The DBI package has a write table command. It uses the same connection, but it also requires that the input table name is wrapped in SQL().

I tested the following and it worked as expected.

data(iris)
DBI::dbWriteTable(connection, SQL("database.schema.iris"), iris)


来源:https://stackoverflow.com/questions/48194938/dbplyr-copy-to-not-saving-table-to-database

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!