Format SQL for Postgres, MySQL, or BigQuery.
A one-liner SELECT with 5 joins and a CTE is basically unreadable. Dialect-aware formatting knows Postgres's ::type casts, BigQuery's backtick identifiers, and MySQL's backtick-vs-quote rules — a generic formatter mangles them.
Step-by-step
- Open /sqlfmt/. Paste your SQL into the input.
- Pick a dialect. Standard SQL, Postgres, MySQL, MariaDB, SQLite, BigQuery, Snowflake, Redshift, Spark, DB2, T-SQL, PL/SQL, N1QL, Hive, Trino — 15 total. This isn't cosmetic; it's about which reserved words are recognized and how identifiers are quoted.
- Set keyword case. UPPER (most conventions), lower, or Preserve if your team style is already set.
- Set indent. 2 or 4 spaces, or tab. Match your team's SQL style guide.
- Click Format. Copy the output.
Why dialect matters
Generic SQL formatters treat every input as ANSI SQL. Real queries aren't ANSI:
- Postgres:
::typecasts,DISTINCT ON,RETURNING, array types,WITH RECURSIVE. - BigQuery: backtick-quoted identifiers,
ARRAY_AGG,STRUCT,EXCEPTfor column exclusion. - Snowflake:
QUALIFY, table sampling,MERGEsemantics. - T-SQL: bracketed identifiers
[dbo].[table],TOP Ninstead ofLIMIT.
Formatting the wrong dialect can silently break the query — a Postgres ::text cast wrapped across a line-break in the wrong place becomes invalid. Pick the dialect.
Example
Before
select id,name,coalesce(email,'-') as email from users u left join orders o on u.id=o.user_id where u.created_at > now() - interval '7 days' group by 1,2,3 order by u.id desc limit 100;
After (Postgres, UPPER, 4-space)
SELECT
id,
name,
COALESCE(email, '-') AS email
FROM
users u
LEFT JOIN orders o ON u.id = o.user_id
WHERE
u.created_at > NOW() - INTERVAL '7 days'
GROUP BY
1, 2, 3
ORDER BY
u.id DESC
LIMIT
100;
Team-shareable presets. Once you land on a house style (say, Postgres + UPPER + 2-space), save the URL with the config in the query string —
?dialect=postgresql&case=upper&indent=2 — and share it with the team. Everyone gets the same formatting without a linter setup.Nothing uploaded
The formatter engine (sql-formatter, MIT) runs entirely in your browser. Your queries — including any embedded secrets, table names, or business logic — never leave the tab.