BigQuery - Missing support for WITH Expressions
Author: MartinLecatCreated Sep 29, 2026Updated Sep 29, 2026
Labelsenhancementbigquery
Search before asking
- I searched the issues and found no similar issues.
Description
In BigQuery, the WITH keyword isn't just for CTEs, it can also be used as a way to create temporary variables when creating a column for example.
It is documented here.
Here is the configuration used for the following tests:
[sqlfluff]
dialect = bigquery
templater = rawAnd here the examples provided by the documentation with the parsing error message from SQLFluff:
SELECT WITH(a AS '123', -- a is '123'
b AS CONCAT(a, '456'), -- b is '123456'
c AS '789', -- c is '789'
CONCAT(b, c)) AS result; -- b + c is '123456789'==== parsing violations ====
L: 1 | P: 8 | PRS | Line 1, Position 8: Found unparsable section: "WITH(a AS '123',
| -- a is '..."
WARNING: Parsing errors found and dialect is set to 'bigquery'. Have you configured your dialect correctly?SELECT WITH(a AS RAND(), a - a);==== parsing violations ====
L: 1 | P: 8 | PRS | Line 1, Position 8: Found unparsable section: 'WITH(a AS RAND(), a
| - a)'
WARNING: Parsing errors found and dialect is set to 'bigquery'. Have you configured your dialect correctly?Use case
There's many thing we can imagine that would be nice to add in SQLFluff:
- A rule for forbidding WITH expressions
- A rule for encouraging WITH expressions when an expressions is getting lengthy or has repetitive bits
- A rule for defining variable case (may not be pertinent, as we could follow column casing but just letting it here)
- A rule for forbidding/forcing the use of "final variables":
SELECT
WITH(
a AS 1,
b AS 2,
-- Here we create a "final variable" that will return the result
result AS a + b,
result
) AS foo,
WITH(
a AS 1,
b AS 2,
-- Here we skip the "final variable" as it's not mandatory
a + b
) AS barDialect
- BigQuery
- Maybe others ? I couldn't find anything but searching is "hard" as you always end up on CTEs pages...
Are you willing to work on and submit a PR to address the issue?
- Yes I am willing to submit a PR!
Code of Conduct
- I agree to follow this project's Code of Conduct
Source: sqlfluff/sqlfluff