Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/postgresql/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
通过r更新postgresql数据库中的表_R_Postgresql - Fatal编程技术网

通过r更新postgresql数据库中的表

通过r更新postgresql数据库中的表,r,postgresql,R,Postgresql,如何使用新数据通过R更新postgresql数据库中的数据 我试过了 dbGetQuery(con,"UPDATE table SET column1=:1,column2=:2, column3=:3 where id=:4", data=Rdata[,c("column1", "column3", "column3","id")]) 我也试过用$替换冒号,但也没用。我不断得到: Error in postgresqlExecStatement(conn, st

如何使用新数据通过R更新postgresql数据库中的数据

我试过了

dbGetQuery(con,"UPDATE table SET column1=:1,column2=:2, column3=:3 
              where id=:4", data=Rdata[,c("column1", "column3", "column3","id")])
我也试过用$替换冒号,但也没用。我不断得到:

Error in postgresqlExecStatement(conn, statement, ...) : 
unused argument(s)

至少RODBC有一个特定的函数sqlUpdate

sqlUpdate更新行已经存在的表。数据帧 dat应包含列 具有映射到表中(某些)列的名称


请参见

我是通过以下方法计算出来的:

update <- function(i) {
drv <- dbDriver("PostgreSQL")
con <- dbConnect(drv, dbname="db_name", host="localhost", port="5432", user="chris", password="password")
txt <- paste("UPDATE data SET column_one=",data$column_one[i],",column_two=",data$column_two[i]," where id=",data$id[i])
dbGetQuery(con, txt)
dbDisconnect(con)
}


registerDoMC()

foreach(i = 1:length(data$column_one), .inorder=FALSE,.packages="RPostgreSQL")%dopar%{
update(i)
}

update您是否查看了文档以了解是否支持占位符?并非每个来自R的db接口都有。我知道RSQLite有,但我很确定RODBC没有,我也不确定RPostgreSQL。