Unfortunately the RpostgreSQL package (I’m pretty sure other SQL DBs as well) doesn’t have a provision to UPDATE multiple records (say a whole data.frame) at once or allow placeholders making the UPDATE a one row at a time ordeal, so I built a work around hack to do the job in parellel. The big problem was that you have to open and close the connections with every iteration or you will exceed max connections since it goes through every row.
First the function for connecting, updating, and closing the DB:
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) }
Then run the query:
QED
[...] http://stathack.wordpress.com/2013/02/27/update-multiple-postgresql-table-records-in-parellel/ [...]