validationpython-sqlsqlglot

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


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.


Solution

  • 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.