sqlglot
sqlglot copied to clipboard
BigQuery multi-line script with variables not supported
The following snippet:
import sqlglot
rendered_sql = "DECLARE threshold INT64 DEFAULT 100;"
sqlglot.parse(rendered_sql, read=sqlglot.Dialects.BIGQUERY)
throws ParseError: Invalid expression / Unexpected token. Line 1, Col: 19.
It doesn't like INT64 in that position.
This is not correct as in a multi-line Sql script, we have a few variables declared at the top which are then used in several queries later on.
For instance,
DECLARE threshold INT64 DEFAULT 100;
SELECT product_id, score
FROM <some-product-table>
WHERE score < threshold
ORDER BY score;
Python: 3.10.6 OS: Mac sqlglot: 10.4.4 installed via pip