Docs
Docs /SQL Editor /SQL formatting
SQL EditorEditor

SQL formatting

One shortcut reflows the statement (or just the lines you've selected) using Prism's parser, so it understands CTEs, pipe syntax, and BigQuery-specific clauses rather than guessing from keywords.

before
1
select u.user_id,u.country,count(*) as total from `ace-analytics.warehouse.users` u join `ace-analytics.warehouse.events` e on u.user_id=e.user_id where u.is_active=true and e.event_date>='2024-01-01' group by u.user_id,u.country order by total desc limit 100
after Format (Pretty, defaults)
12345678910
SELECT
u.user_id,
u.country,
count(*) AS total
FROM
`ace-analytics.warehouse.users` u JOIN `ace-analytics.warehouse.events` e ON u.user_id = e.user_id
WHERE u.is_active = true AND e.event_date >= '2024-01-01'
GROUP BY u.user_id, u.country
ORDER BY total DESC
LIMIT 100

Formatting a query

  • Press F (CtrlShiftF on Windows and Linux).
  • Open the ⋮ menu at the top right of the editor and choose Format.
  • Press K and run Format SQL from the command palette.
  • Right-click in the editor and choose Format SQL.
editor ⋮ menu

Formatting is one undo step: Z puts the original back. The cursor stays where it was. If the SQL doesn’t parse, nothing changes.

Formatting only a selection

Select part of the statement and press the same shortcut: only the selection is reformatted, the rest is untouched. This is the way to fix one messy CTE in an otherwise clean query.

1234567
WITH active AS (
select * from `ace-analytics.warehouse.users` where is_active=true
),
recent AS (
SELECT * FROM `ace-analytics.warehouse.events`
)
SELECT * FROM active

becomes

12345678910
WITH active AS (
SELECT
  *
FROM `ace-analytics.warehouse.users`
WHERE is_active = true
),
recent AS (
SELECT * FROM `ace-analytics.warehouse.events`
)
SELECT * FROM active

Changing keyword case only

The two Convert keywords to … items in the ⋮ menu change keyword case without touching layout. Shortcuts: U for UPPERCASE, L for lowercase. Function names are left as written either way: count(*) stays count(*).

Choosing a formatting mode

Settings → Editor → SQL Formatting → Formatting Mode.

ModeResult
Pretty (default)One clause per line, lists indented (the example at the top)
CompactSingle line, minimal whitespace; for logs and chat
PreserveKeeps your layout; only the options below (keyword case, quoting, AS) are applied
Compact
1
SELECT u.user_id,u.country,count(*) AS total FROM `ace-analytics.warehouse.users` u JOIN `ace-analytics.warehouse.events` e ON u.user_id=e.user_id WHERE u.is_active = true AND e.event_date >= '2024-01-01' GROUP BY u.user_id,u.country ORDER BY total DESC LIMIT 100

Tuning the output

All in Settings → Editor → SQL Formatting.

SQL FormattingConfigure how SQL queries are formatted (Cmd+Shift+F / Ctrl+Shift+F)
Formatting Mode
PreserveKeep original formatting
Pretty (default)Multi-line with indentation
CompactSingle-line, minimal whitespace
Keyword Case
UPPER (default)Convert keywords to uppercase (SELECT, FROM, WHERE)
lowerConvert keywords to lowercase (select, from, where)
preserveKeep original keyword case
Indentation
Indent Size 2
Number of spaces or tab width for indentation
SpacesUse spaces or tabs for indentation
Layout Options
Newline After ClauseAdd newline after major SQL clauses (SELECT, FROM, WHERE, etc.)
Max Line Length 80
Maximum line length before wrapping (in characters)
Trailing CommaAdd comma after last item in lists (better for git diffs)
Format on TypeAutomatically format SQL as you type (e.g., after pressing Enter)
OptionValuesDefault
Formatting ModePreserve · Pretty · CompactPretty
Keyword CaseUPPER · lower · preserveUPPER
Indent Size2 · 4 · 82
Indent styleSpaces · TabsSpaces
Newline After Clauseon · offon
Max Line Length80 · 100 · 12080
Trailing Commaon · offoff
Quote IdentifiersPreserve · Always · NeverPreserve
AS KeywordPreserve · Always · NeverPreserve
Pipe Operator StyleStandard · Left-AlignedStandard
Format on Typeon · offoff

Quote Identifiers: Always backticks every table and column name (`table`.`column`); Never strips them all. Leave it on Preserve unless you know no identifier needs quoting.

AS Keyword: Always writes id AS user_id for every alias; Never writes id user_id.

Pipe Operator Style: applies to pipe syntax. Standard indents |> with the content; Left-Aligned puts |> at column 0 and indents the operator keywords.

Format on Type: reformats as you go, for example after Enter. Off by default.