To be clear, you're looking to use the Query Builder in a Query JSON as SQL query, but the query itself is running into syntax issues. Do you have prepared statements currently enabled or disabled?
I wonder if this somewhat out-of-the-box option would work for you—it uses the alasql library and a Javascript query. If you import the alasql library as an app library, you can then reference the query builder inside the JS query like so:
const data = query1.data
const query = "select * from ? " + queryBuilder1.asSql.replaceAll('"', '')
return alasql(query, [data]);