sqlglot icon indicating copy to clipboard operation
sqlglot copied to clipboard

BigQuery multi-line script with variables not supported

Open insectatorious opened this issue 3 years ago • 0 comments

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

insectatorious avatar Jan 12 '23 22:01 insectatorious