Execute sql with '?' as parameter
Hello everyone.
Please, how do I execute a sql that uses as a parameter the character '?' ?
For example
const sql = 'select * from table where filter = ?'
db.execute(sql, ['filter'])
And the question would be specifically about the ? character, as I can't use a template string in my case
2 Replies
you can use
sql template will handle that for you
Hello, thank you for the response.
But this way doesn't work for me. What I need to do is combine several SQL queries made in Drizzle into a UNION. So, I'm trying to use the sql.toSql() command on these multiple SQL queries, converting them to strings and manually adding the UNION. However, I can't find a way to execute an SQL query returned by the toSql() function because it returns the parameters with "?". That's why I'm wondering how to execute queries with "?", because it seems a bit strange to me that there isn't a way to execute an object returned by toSql().
Hello @Andrew Sherman , I apologize for mention you here, but I'd like to inquire about the possibility of addressing my doubt. As drizzle lacks a UNION function, I wonder if there is a way to "group" multiple SQLs generated with the toSQL() function, which could be quite helpful.