R Multiple queries via RODBC in MySQL

23 Views Asked by At

I want to do a lot of updates in one query in MySQL:

require(RODBC)

q <- "UPDATE myTable SET NumberOfSignals=4 WHERE ItemID=1361; "
q <- paste(q,"UPDATE myTable NumberOfSignals=5 WHERE ItemID=1362; ")
q <- paste(q,"UPDATE myTable NumberOfSignals=6 WHERE ItemID=1363; ")

res <- sqlQuery(con, q, stringsAsFactors = FALSE)

In mySQL I got an error message:

MySQL][ODBC 8.3(w) Driver][mysqld-8.0.20]You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'UPDATE...

It happens because of multi-query limitation in MySQL. I have tried to use multiResults=TRUE in sqlQuery but I have a message the argument is not used.

I know that I can do a loop and update one by one, but for performance reasons I would like to avoid it. There could be a few thousands of updates in one query.

Is there a way to change MySQL configuration, this database schema or just the query alone and make multi-queries working?

0

There are 0 best solutions below