Skip to content

Bigquery Rules ​

This section contains 1 rule(s) related to bigquery.

Rule Summary ​

CodeNameAliasesFix Compatible
BQ01bigquery.forbid_with_expressions-❌

BQ01: bigquery.forbid_with_expressions ​

Forbid BigQuery WITH expressions.

PropertyValue
Namebigquery.forbid_with_expressions
Groupsall, bigquery
Auto-fixableNo ❌

BigQuery's WITH expression assigns variables inside an expression and then evaluates a final expression:

sql
SELECT WITH(a AS 1, b AS a + 1, b * 2) AS total;

Some teams prefer to keep statements to CTEs, subqueries or plain expressions, and to avoid this construct entirely. This rule flags every WITH expression in the bigquery dialect.

This rule only applies to the bigquery dialect and is disabled by default. Enable it with the forbid_with_expressions = True flag.

Anti-pattern

Using a WITH expression.

sql
SELECT WITH(a AS 1, a) AS x;

Best practice

Rewrite the expression without WITH.

sql
SELECT 1 AS x;

Configuration

OptionDescription
forbid_with_expressionsIf True, flag every BigQuery WITH expression. Defaults to False. Must be one of [True, False].

Released under the MIT License.