I am trying to generate a bunch of SQL scripts using DBI::sqlInterpolate
function but constantly get SQL error as the script embeds quotes that are returned with the R variable.
Here is the code:
> x<-'state_transtions'
> y<-'transition_time'
> script<-"select * from ?x WHERE DATE(?y)> DATE_SUB(NOW(), INTERVAL 1 DAY)"
> sqlInterpolate(ANSI(),script,x=x,y=y)
#<SQL> select * from 'state_transtions' WHERE DATE('transition_time')> DATE_SUB(NOW(), INTERVAL 1 DAY)
As you see I am generating the desired SQL table names and column names through R code. Hence the injection values (?x, ?y) are passed as variables.
I looked up this link which was closest to find me a solution but honestly, I do not understand it. [https://rstats-db.github.io/DBI/reference/sqlParseVariables.html#examples]