0

I try to update a row in my sql database using R. Therefore I use the following statement:

 s <- sprintf("UPDATE `match_data` SET `distance` = '%a' WHERE 'Match.ID' = '%a'", distance, id)
 check <- dbGetQuery(con, s)

Where distance and id are both numeric values. And the columns in which I try to update the values are both of type bigint(10).

When I run the query I do not get an error. However, the values do not seem to update. Any thought where this goes wrong?

Jonathan Leffler
  • 730,956
  • 141
  • 904
  • 1,278
Frank Gerritsen
  • 185
  • 5
  • 14

1 Answers1

1

The dbGetQuery only works for SELECT statements. For data manipulation (i.e. UPDATE, DELETE, INSERT INTO, DROP TABLE,..) you may use dbSendStatement or dbExecute which is easier to use.

You may check the doc for more info. https://cran.r-project.org/web/packages/DBI/DBI.pdf

RZRKAL
  • 417
  • 4
  • 12