--rules flag.
multi-statement
Rule Details
Rule Details
Severity: error
Name:
Category: CorrectnessDetects when multiple SQL statements are combined into a single query block (separated by semicolons).Why this is an error:
Name:
multi-statementCategory: CorrectnessDetects when multiple SQL statements are combined into a single query block (separated by semicolons).Why this is an error:
- CTEs (
WITHclauses) from the first statement are not visible to subsequent statements - Each statement executes independently, breaking expected scoping
- This pattern can silently cause runtime errors
- You’re extracting SQL from application code where multi-statement blocks shouldn’t exist
- You’re building a query builder or ORM and want to prevent statement concatenation bugs
- You’ve been bitten by CTE scope issues before
- Migration files that intentionally batch multiple DDL statements
- Admin scripts that combine multiple operations
- SQL dumps or schema exports
Problematic Examples
Problematic Examples
DELETE will fail at runtime with:Correct Examples
Correct Examples
How to Enable
Use the--rules flag to explicitly enable opt-in rules:
Implementation Details
Themulti-statement rule is unique because it operates on the full parse result rather than individual statements:
Check(stmt *pg_query.RawStmt, sql string) method which operates on a single statement.
Why is this Opt-In?
Themulti-statement rule is opt-in because:
-
Migration files legitimately batch multiple DDL statements together:
-
Schema dumps and backups contain hundreds of statements:
-
Admin scripts often combine operations for convenience:
- ORM-generated SQL in some frameworks may include semicolons
Use Cases
When to Enable
Application code analysis:When NOT to Enable
Migration files:Real-World Example
Consider this bug thatmulti-statement would catch:
Next Steps
Default Rules
Explore the 15 rules that run by default
Rules Overview
Understand the rule system architecture