Skip to main content

SQL Formatting

Format your SQL with Cmd+Shift+F (Mac) or Ctrl+Shift+F (Windows/Linux).


Formatting Modes

Pretty (Default)

Clean, readable formatting with consistent indentation.

-- Before
select u.id,u.name from users u where u.active=true order by u.name;

-- After
SELECT
u.id,
u.name
FROM users u
WHERE u.active = true
ORDER BY u.name;

Compact

Minimal whitespace for storage and logs.

SELECT u.id,u.name FROM users u WHERE u.active=true ORDER BY u.name;

Preserve

Maintains original formatting exactly.


Options

Configure in Settings → Editor → SQL Formatting.

OptionValuesDefault
Keyword CaseUPPERCASE, lowercase, PreserveUPPERCASE
Indent StyleSpaces, TabsSpaces
Indent Size2, 4, 82
Max Line Length80, 100, 12080

Format Selection

Select a portion of SQL, then press the format shortcut. Only the selected portion formats.

WITH messy_cte AS (
select * from users where active=true -- Select and format just this
),
clean_cte AS (
SELECT * FROM orders
)

Shortcuts

ActionMacWindows/Linux
Format Document/SelectionCmd+Shift+FCtrl+Shift+F