1
Hello, everybody
I have a problem in knowing how to insert two commands (INSERT and UPDATE) in the same instruction in Sqlite, via R Language.
I don’t know if this is impossible due to Sqlite or R’s DBI package deficiency.
Follow image, with reproducible example, about what I’m trying to do:
con <- DBI::dbConnect(RSQLite::SQLite(), ":memory:")
DBI::dbWriteTable(con, "cars_a", head(cars, 3))
DBI::dbWriteTable(con, "cars_b", head(cars, 3))
DBI::dbExecute(con,
"INSERT INTO cars_a
VALUES (10, 10 );
UPDATE cars_b
SET dist = 400
WHERE speed = 7;"
DBI::dbReadTable(con, "cars_a")
DBI::dbReadTable(con, "cars_b")
NOTE: Although the tables are named as "cars_a" and "cars_b" interpret that they are related. In my case, as I am working with a Web Scraping, INSERT has the purpose of aggregating data in the table with the data scraped, and UPDATE updates the request table.
After trying several ways, I could only execute the first SQL statement. As shown below:
NOTE: I need to have both commands in the same SQL statement to ensure that INSERT and UPDATE will be done. The solution I’m adopting today is to put the commands in separate instructions, but it’s not the idea when it comes to performance and information security bias.
– George Santiago
George, edit the question, add that remark. Also, add your code, not image, so anyone who wants to simulate, test, facilitate, and better organized!
– rbz
Please edit the question with copy/Paste of the instructions, not as images. With the code we can copy to an R session and test, with images we can’t, we have to enter everything again via keyboard.
– Rui Barradas