This document captures current formatting heuristics and examples. It is intentionally non-stable and may evolve as formatter quality improves.
For stable guarantees, see format-contract.md.
- Line length: 100
- Indent width: 2 spaces
- Keyword case: UPPER
- Dialect: ANSI (see
dremio.mdfor Dremio rules) - Select list style:
auto(small/medium/large tiers)
- Keep the select list inline when the estimated first line (
SELECT+ list + firstFROM/JOIN) fits withinline_length. - Switch to per-line select items when the inline form would overflow, or when
select_list_style = per_line. - Single wildcard projections stay inline (
SELECT * FROM ...) unless theFROMblock already breaks.
Inline example:
SELECT a, b FROM t;Per-line example:
SELECT
a,
b,
c AS alias_c,
CASE
WHEN x > 0 THEN 'positive'
ELSE 'other'
END AS category
FROM t;Hanging-line select lists are not used:
-- not used
SELECT a, b, c,
d, e, f
FROM t;- Clause order:
SELECT,FROM,WHERE,GROUP BY,HAVING,WINDOW(if any),QUALIFY(if supported),ORDER BY,LIMIT/FETCH,OFFSET - Each clause starts on its own line (except small inline
SELECT) FROMbase relation on its own line; eachJOINon a new line aligned withFROM- Join token style is preserved (
JOINremainsJOIN;INNER JOINremainsINNER JOIN) ONis indented one level under its joinWHERE/HAVING/QUALIFYbreak logical conditions across linesGROUP BYrenders one item per line when more than one expression is presentORDER BYmay stay inline for short lists, but uses per-line layout for larger/longer listsLIMIT/OFFSET/FETCHstay on one line when practical
Join example:
FROM base_table AS b
INNER JOIN dim AS d
ON d.id = b.dim_id
LEFT JOIN f
ON f.id = b.fact_id- Emit a blank line between consecutive top-level statements
- When a query has CTEs, leave a blank line between the CTE list and the main query body
WITHon its own line- Each CTE uses
name AS (...) - CTE body is indented
WITH cte AS (
SELECT a, b FROM t
),
other AS (
SELECT x FROM cte
)
SELECT * FROM other;- Keep short subqueries inline when readable
- Otherwise, use multiline parenthesized layout with indented body and aligned closing
) - Scalar subqueries in expressions prefer multiline layout when non-trivial
CASEuses multiline form when not short enough to remain inlineWHEN/THEN/ELSEclauses break onto separate lines in multiline form- Nested boolean expressions break at
AND/ORwith indented groups
- Preserve quoted identifiers as-is
- Apply keyword casing to recognized keywords only
- Preserve string literal casing and contents
- Preserve inline and block comments relative to nearby SQL where possible
- Numeric thresholds for select-list layout tiers
- Additional select-list style modes
- More explicit knobs for clause wrapping thresholds