Get glue to use a string within the sql generated

yr <- '2020'
mt <- '03'
d <- '17'
game_name <- 'fungame'

I have a sql file and it looks like this:

# update_hive_partition.sql
ALTER TABLE {rlang::parse_exprs(glue('revenue_predictions.{game_name}'))} ADD IF NOT EXISTS
PARTITION (year={yr}, month={mt}, day={d})
location {rlang::parse_exprs(glue('"s3://ourco-emr/tables/revenue_predictions.db/{game_name}/year={yr}/month={mt}/day={d}"'))}

Looks like this:

> update_partitions_query
<SQL> 
ALTER TABLE revenue_predictions.fungame ADD IF NOT EXISTS
PARTITION (year='2020', month='03', day='17')
location s3://ourco-emr/tables/revenue_predictions.db/fungame/year=2020/month=03/day=17

I need the location to be enclosed in single quotes. Desired result:

> update_partitions_query
<SQL> 
ALTER TABLE revenue_predictions.fungame ADD IF NOT EXISTS
PARTITION (year='2020', month='03', day='17')
location 's3://ourco-emr/tables/revenue_predictions.db/fungame/year=2020/month=03/day=17'

Tried just adding single quotes:

... location {rlang::parse_exprs(glue('s3://glu-emr/tables/revenue_predictions.db/{game_name}/year={yr}/month={mt}/day={d}'))}/month=03/day=17'
Error in parse(text = x) : <text>:1:4: unexpected '/'
1: s3:/
       ^

Also tried just using double quotes. Tried single quotes nested in double quotes and vice versa. I cannot seem to get my desired result.

How can I generate sql where the location parameter is quoted?

see this How to change the quotation character(s) for glue_sql?

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.