SQLFORMAT

Formats a SQL string according to a configurable style preset, with optional overrides for indentation, keyword casing, comma placement, and line width.

Category: utilityDeltaForge extension

Syntax

SQLFORMAT '<sql>' [STYLE DEFAULT|COMPACT|ENTERPRISE|REDGATE|UPPERCASE|LOWERCASE]

Description

## Overview SQLFORMAT takes a raw SQL string and applies consistent formatting according to the selected style preset. It is useful for standardizing SQL code style across teams, generating readable output from dynamically constructed queries, and preparing SQL for documentation or code review. ## Behavior The engine parses the input SQL string, builds a formatting configuration from the selected style (and any option overrides), then produces the formatted output. The result is a single-row result set with one column: **formatted_sql**. ### Style Presets | Style | Keyword Case | Indentation | Commas | Notes | |-------|-------------|-------------|--------|-------| | DEFAULT | Uppercase | 4 spaces | Trailing | Standard formatting suitable for most environments. | | COMPACT | Preserve | Minimal | Trailing | Minimizes whitespace; useful for embedding SQL in code. | | ENTERPRISE | Uppercase | 4 spaces | Trailing | Formal style with consistent spacing and line breaks. | | REDGATE | Uppercase | 4 spaces | Leading | SQL Prompt-compatible style with commas at line start. | | UPPERCASE | Uppercase | Preserve | Preserve | Only changes keyword casing; layout is preserved. | | LOWERCASE | Lowercase | Preserve | Preserve | Only changes keyword casing to lowercase; layout is preserved. | ### Option Overrides Individual formatting parameters can be overridden via the OPTIONS clause: - **indent_size** / **indent**: Number of spaces per indentation level (integer). - **keyword_case** / **case**: Keyword casing strategy (upper, lower, preserve, capitalize). - **comma_style** / **commas**: Comma placement (trailing, leading). - **max_line_width** / **line_width**: Maximum line width before wrapping (integer). - **use_tabs** / **tabs**: Use tab characters instead of spaces (true/false). Options are applied after the style preset, so they selectively override specific aspects while inheriting the rest from the preset. ## Compatibility SQLFORMAT is a DeltaForge extension. It uses the same formatting engine that powers the VS Code extension's Format Document command and the LSP formatting provider.

Parameters

NameTypeDescription
sqlSQL string to format.
styleStyle: DEFAULT, COMPACT, ENTERPRISE, REDGATE, UPPERCASE, LOWERCASE.

Examples

-- Format with the default style
SQLFORMAT 'select id,name from users where active=true';
-- Format with the Enterprise style
SQLFORMAT 'select id,name,email from users where active=true and role=''admin''' STYLE ENTERPRISE;
-- Format with the Compact style
SQLFORMAT 'SELECT o.id, o.total, c.name FROM orders o JOIN customers c ON o.customer_id = c.id WHERE o.status = ''shipped''' STYLE COMPACT;
-- Format with custom options overriding the default style
SQLFORMAT 'select a,b,c from t where x>1' OPTIONS (indent_size = '2', comma_style = 'leading');
-- Uppercase all keywords while preserving layout
SQLFORMAT 'select count(*) as cnt from orders group by region having cnt > 10' STYLE UPPERCASE;

Pitfalls

Open in interactive docs →   DeltaForge home →