I am using the library RMySQL
to generate an SQL statement
query <- sprintf("foo", paste(mydf, collapse = "', '",sep = ','))
When i have a look at the query it seems to be putting everything in brackets for example a column would consist of monatory terms 10.50, 20.50, 50.33
but when i look at the SQL it has it as c(10.50,20.50, 50.33)
which causes my SQL to crash. Does anyone know why?
Reproducible example
mydf <- data.frame(
X = sample(1:10),
Y = sample(c("yes", "no"), 10, replace = TRUE)
)
# Construct the update query by looping over the data fields
query <- sprintf("INSERT INTO feedback (X,Y) VALUES ('%s')",
paste(mydf, collapse = "', '",sep = ','))
> cat(query)
INSERT INTO feedback (X,Y) VALUES ('c(8, 6, 10, 9, 3, 4, 5, 7, 2, 1)', 'c(1, 2, 1, 2, 2, 1, 1, 1, 2, 2)')
Thanks