I'm currently trying to create a temp table or a table or a View on the fly using glue::sql.
I understand and know how to build up a sql query using glue by passing in R objects as parameters, however:
Is it possible to pass in an object that is converted into SQL syntax for creating a table?
for example my sql glue statement is the following:
sql_query <- glue::glue_sql(
"create {create_type} some_table as
select * from {`table_name`}
where
({`table_name`}._start_time >= {start}
and
{`table_name`}._end_time <= {end})
or
({`table_name`}.type == 'internet'
and
{`table_name`}._start_time >= {start}
and
{`table_name`}.end_time <= {end} + 604800)
",
.con = conn
)
I want to be able to pass a parameter such as 'TEMP TABLE' to {create_type}
so that it will be able to become: "create TEMP TABLE some_table as...."
I have not seen any examples where this has been done, so wondered if it is possible?