(Sorry if this is very basic, I'm just not able to figure out)
I have a table t sitting in a mysql db, which looks like this: (Name is the primary key)
Current Table in DB
Name Balance
Bob 100
Ted 150
Carl 130
I also have a data.frame in R reflecting changed balances
data.frame in R
Name Balance
Bob 90
Ted 170
Bill 50
I want to perform the equivalent of a mysql replace, so that my table gets updated to reflect the new balances
Desired Table in DB
Name Balance
Bob 90
Ted 170
Carl 130
Bill 50
I'm currently using the RMySQL package- I tried doing this with dbWriteTable, but am not able to get this to work.
Eg1 ("Insert")
dbWriteTable(dbConnection, 'tableName', df, row.names=F, append=T)
Produces
Name Balance
Bob 100
Ted 150
Carl 130
Bill 50
Eg2 ("Overwrite")
dbWriteTable(dbConnection, 'tableName', df, row.names=F, append=F, overwrite=T)
Produces
Name Balance
Bob 90
Ted 170
Bill 50
How do I do a replace?
dbWriteTable
, though. Would you simply write a specific replace query and send it like any otherselect
,delete
, orinsert
query? – Levenson