Ignoring certain parts of the sql #407
-
Hi, I have a question for which sadly i havent found the answer for in the doc. Within my sql query i have some placeholders for a couple of functions that i replace with query before the sql runs. Example: Is there any way i can ignore these placeholders basically everything within {{*}} when parsing with sqlglot? Thanks |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Assuming you're using jinja, you should render it first, so parse_one(render(sql)). SQLGlot needs to parse SQL. You could also use regex to remove {{ }} assuming that the resulting sql is still valid. The reason why we don't parse Jinja is because Jinja operates on the string level and can be put anywhere, it's impossible to parse everything that Jinja can do. |
Beta Was this translation helpful? Give feedback.
Assuming you're using jinja, you should render it first, so parse_one(render(sql)). SQLGlot needs to parse SQL.
You could also use regex to remove {{ }} assuming that the resulting sql is still valid. The reason why we don't parse Jinja is because Jinja operates on the string level and can be put anywhere, it's impossible to parse everything that Jinja can do.