通过r更新postgresql数据库中的表
如何使用新数据通过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
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。