Clarify Structure
Makes implicit SQL structure explicit with parentheses. Enabled by default.
Two structural clarifications:
- AND/OR precedence: wraps AND groups inside OR in parens
- Set operations: wraps each operand of UNION/INTERSECT/EXCEPT in parens with
) OPERATOR (hinges
AND/OR precedence
SQL precedence: AND binds tighter than OR. a OR b AND c means a OR (b AND c). This transform makes the grouping visible.
SELECT a FROM t WHERE x = 1 OR y = 2 AND z = 3
select a from t where x = 1 or (y = 2 and z = 3)
Without clarifyStructure
SELECT a FROM t WHERE x = 1 OR y = 2 AND z = 3
select a from t where x = 1 or y = 2 and z = 3
Set operations — UNION ALL
Each operand wrapped in parens. The ) UNION ALL ( hinge stays on one line.
SELECT customer_id, name FROM active_customers WHERE status = 'active' UNION ALL SELECT customer_id, name FROM archived_customers WHERE status = 'archived'
(select customer_id, name from active_customers where status = 'active') union all (
select customer_id, name
from archived_customers
where status = 'archived'
)
Short UNION ALL collapses to one line
SELECT a FROM t1 UNION ALL SELECT b FROM t2
(select a from t1) union all (select b from t2)
Three-way set operation
SELECT a FROM t1 UNION ALL SELECT b FROM t2 INTERSECT SELECT c FROM t3
(select a from t1) union all (select b from t2) intersect (select c from t3)
Without clarifyStructure — UNION ALL trails
SELECT a FROM t1 UNION ALL SELECT b FROM t2
select a from t1 union all select b from t2
Set operations inside CTE
WITH combined AS (SELECT a FROM t1 UNION ALL SELECT b FROM t2) SELECT * FROM combined
with combined as ((select a from t1) union all (select b from t2))
select *
from combined