Re: [R] INSERT OR UPDATE

2011-05-02 Thread Mikkel Grum
Thanks Steven. It obviously makes sense to loop on the much smaller dataset that is being added than the set of everything that might already be in the database. I've added your message in plain text, so that others can see it too. Mikkel From: Steven Kennedy Subject: Re: [R] INSE

Re: [R] INSERT OR UPDATE

2011-05-02 Thread Steven Kennedy
Rather than selecting all the keys, then having R loop through them, why not have postgres do it for you with something like: #go through each line in our entry table for (i in 1:dim(tbl)[1]){ #check if the pkey already exists q <- paste ("SELECT key1, key2 FROM tabl WHERE key1=",tbl[i,1],

[R] INSERT OR UPDATE

2011-05-02 Thread Mikkel Grum
I'm trying to insert rows of a data.frame into a database table, or update where the key fields of a record already exist in the table. I've come up with a possible solution below, but would like to hear if anyone has a better solution. # The problem demonstrated: # Create a data.frame with tes