Problem: I want to update values (in multiple rows and columns) of a table in a postgres database using R.
I know that the sql update statement can be something like this but I assume looping over a set of such queries is inefficient:
UPDATE table
SET col1 = value1, col2 = value2, ...
WHERE col1 = "some-value"
Question: Is there a function available to only update particular rows (and potentially only a subset of the columns) of the table (similar to dbWriteTable
)? If not, can you think of an efficient way/sql query of updating multiple rows in postgres and how to hand over the R object to the sql query?
EDIT: Assuming I have a foreign key and I don't want to turn on the ON DELETE CASCADE option, how could I efficiently update values in multi rows and columns for the parent table (I only want to update parent table, not child table)?