我们如何使用R将数据写入Postgres DB表? [英] How we can write data to a postgres DB table using R?

查看:107
本文介绍了我们如何使用R将数据写入Postgres DB表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要使用R将数据写入postgres DB表。如果表中存在ID数据,则应更新数据,否则应将新数据追加到表中。



我使用'RPostgreSQL'软件包尝试了此错误消息

I need to write data to a postgres DB table using R. If a data exist for an ID in the table, data should be updated otherwise new data should append to the table.

I tried this using 'RPostgreSQL' Package I got this error message

dbWriteTable(con, 'credit', credit,overwrite=TRUE,row.names=FALSE,append=TRUE)<br>

Error in postgresqlWriteTable(conn, name, value, ...) :overwrite and append cannot both be TRUE


推荐答案

您不能一次使用覆盖和追加。如果使用如下所示的overwrite命令,它将截断表并重写数据。

You cannot use overwrite and append at once. If use overwrite command as follows, it will truncate the table and rewrite the data.

dbWriteTable(con, 'credit', credit,overwrite=TRUE,row.names=FALSE)

如果使用添加,它将添加行。但这不会更新您的结果。

If use append it will Add the rows. But it won't update your results.

dbWriteTable(con, 'credit', credit,row.names=FALSE,append=TRUE)

这篇关于我们如何使用R将数据写入Postgres DB表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆