0

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 Answers1

1

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.

Toby Mao
  • 374
  • 2
  • 6
  • Databricks SQL allows those Jinja style parameters, [like so](https://docs.databricks.com/_images/parameter-example.png). Would you say that what is written in the Query Explorer is not necessarily SQL? – user16458812 Dec 27 '22 at 20:37
  • Databricks has a preprocessor that allows you to have variable substitution or string manipulation. It is not standard SQL -- it's not part of the ansi sql spec. Preprocessors are not a part of the language because they are meta, they can dynamically change the actual SQL produced making it very difficult to parse. – Toby Mao Dec 29 '22 at 17:54