Style Guide Rule Mapping

How sqlfmt maps to the Simon Holywell SQL Style Guide.

Enforced Rules

These rules are automatically applied by sqlfmt on every format.

RuleDescription
Right-aligned keywordsClause keywords (SELECT, FROM, WHERE, AND, OR, JOIN, etc.) are right-aligned to a per-statement river width
Uppercase keywordsAll SQL reserved words are uppercased (SELECT, FROM, WHERE, INSERT, etc.)
Lowercase identifiersUnquoted identifiers (table names, column names) are lowercased; quoted identifiers are preserved as-is
Trailing commasColumn lists use trailing commas with continuation lines indented past the river
No trailing whitespaceAll trailing whitespace is stripped from every line
Consistent indentationContinuation lines, subexpressions, and nested blocks are indented predictably relative to the river
JOIN alignmentJOIN, INNER JOIN, LEFT JOIN, etc. are right-aligned with ON/USING clauses properly indented
Subquery indentationSubqueries are indented with their own derived river width
CTE formattingWITH / AS blocks are formatted with aligned clause keywords inside each CTE body
CASE expression formattingWHEN/THEN/ELSE/END are consistently indented within CASE blocks
Semicolon terminationStatements are terminated with semicolons

Partially Supported Rules

These rules are addressed but may not cover all edge cases.

RuleDescriptionNotes
Operator spacingSpaces around comparison and arithmetic operators (=, <>, +, -, etc.)Handled for most operators; some PostgreSQL-specific operators (e.g., @>, `?
Line lengthLong expressions are wrapped to multiple linesWrapping is driven by column count heuristics rather than a strict character limit; no configurable max line width
Alignment of VALUESINSERT ... VALUES rows are formattedMulti-row VALUES lists are formatted but column alignment across rows is not guaranteed

Not Enforced

These guidelines from sqlstyle.guide are not enforced by sqlfmt because they involve semantic or naming decisions that a formatter cannot reliably make.

RuleDescriptionReason
Avoid SELECT *Use explicit column listsSemantic decision; the formatter preserves SELECT * as-is
Table/column naming conventionsAvoid abbreviations, use snake_case, avoid reserved words as namesNaming is a design decision, not a formatting concern
Correlation name rulesUse first letters of table name, avoid AS for column aliasesNaming convention; sqlfmt preserves user-chosen aliases
Uniform suffixesUse _id, _status, _date, etc.Schema design convention
Query structure guidelinesAvoid vendor-specific syntax, use ANSI joinssqlfmt formats whatever syntax is used, including vendor extensions

Intentional Deviations

sqlfmt makes a small number of deliberate choices that differ from or extend sqlstyle.guide:

Deviationsqlfmt behaviorRationale
River width is per-statementEach statement derives its own river width from its longest aligned keyword rather than using a fixed columnProduces tighter output for simple queries while accommodating wide keywords like RETURNING in DML
Keyword uppercasing scopesqlfmt uppercases all recognized SQL keywords, including function-like keywords (COALESCE, NULLIF, EXTRACT, etc.)Consistent treatment of all reserved words
Boolean literalsTRUE, FALSE, and NULL are uppercasedTreated as keywords for consistency, matching the guide's general uppercase-keywords rule