SQLGlot is throwing an errow when trying to parse a parameter in a SQL statement, i.e "{{parameter}}"

1.4k views Asked by At

Example query:

SELECT * FROM table
WHERE parameter is {{parameter}}

It's throwing a sqlglot.errors.ParseError. Is there an option to enable this type of option/parameter interpolation, as found in Databricks SQL queries for example?

I want to be able to validate SQL as a part of testing, so I don't want to strip the {{ and }} tokens.

1

There are 1 answers

2
Toby Mao On BEST ANSWER

SQLGlot only parses SQL. since {{ parameter }} is not SQL, it cannot be parsed. You need to first render the parameter, and then SQLGlot can parse the result.