Selecting table as an argument
Hey, this package is great. I'm just having one issue with trying to pass the table as an argument, e.g.
table = "foo"
runquery(conn, sql`CREATE TABLE $table (email text, userid integer)`)
Where the runquery is the one in the README.
Now, the code above does not work. I presume that the issue is that the argument foo is passed to the query as a string or something. Any way around this?
I am having the same issue here. Would be nice if we could still somehow have regular string substitutions for these situations
Oh, actually I think I've solved it. Looks like there is a Literal object you can create (https://github.com/JuliaComputing/SQLStrings.jl/blob/main/src/SQLStrings.jl#L6)
So for instance you can do
function foo(conn::Connection, table::String)
table_literal = SQLStrings.Literal(table)
query = sql`SELECT * FROM $table_literal`
execute(conn, query)
end
foo(conn, "db_table")
In this case sql`SELECT * FROM $table_literal` ends up becoming SELECT * FROM db_table