How do I return a string with only single quotes from the glue::glue_sql command? I have tried two different approaches:
Approach 1
con <- RAthena::dbConnect(RAthena::athena(),
s3_staging_dir = s3_staging_dir)
column_values <- c("thing1","thing2","thing3")
query1 <- glue::glue_sql("SELECT COUNT (*) as venues FROM schema.table WHERE column IN ({column_values*})", .con = con)
query1
This returns:
'SELECT COUNT (*) as venues FROM schema.table WHERE column IN (\'thing1\', \'thing2\', \'thing3\')'
Approach 2
con <- RAthena::dbConnect(RAthena::athena(),
s3_staging_dir = s3_staging_dir)
column_values <- c("thing1","thing2","thing3")
query2 <- glue::glue_sql("SELECT COUNT (*) as venues FROM schema.table WHERE column IN ({`column_values`*})", .con = con)
query2
this returns:
'SELECT COUNT (*) as venues FROM schema.table WHERE column IN ("thing1", "thing2", "thing3")'
My desired output
"SELECT COUNT (*) as venues FROM schema.table WHERE column IN ('thing1', 'thing2', 'thing3')"
Name your vector:
Then use the
{vars*}syntax:Edit: see discussion below - this appears to be local to me and NOT a good answer to the question.