SQL Formatter
Beautify SQL per dialect, including MySQL and PostgreSQL
What is SQL Formatter?
A SQL formatter rewrites single-line or inconsistently indented statements into readable SQL with proper line breaks and alignment, and it understands the keyword differences between MySQL, PostgreSQL, SQL Server, SQLite, BigQuery, and other dialects. Everything runs inside the browser, so your SQL is never uploaded.
How to use SQL Formatter
- 1Paste your SQL — a single statement or several separated by semicolons.
- 2Choose the target dialect; dialects differ in how they handle quoting, functions, and reserved words.
- 3Pick a keyword case style (upper, lower, or preserve) and an indentation width.
- 4Copy the formatted output, or keep adjusting the options until it matches your team conventions.
How do I do this in code?
Use the tool above for one-off work; for anything you repeat, move it into a script or your project.
import { format } from 'sql-formatter';
const pretty = format(sql, {
language: 'postgresql',
keywordCase: 'upper',
tabWidth: 2,
});Common errors and how to fix them
| Symptom | Cause | Fix |
|---|---|---|
| Dialect-specific syntax is broken apart in the formatted output | The selected dialect does not match the SQL you pasted — parsing a PostgreSQL :: cast as MySQL, for instance. | Switch the dialect to the database the statement actually targets. |
| SQL containing template variables fails to format | The {{ }} or :param placeholders from an ORM template are not valid SQL tokens. | Substitute literal values for the placeholders before formatting, or leave that fragment as-is and skip it. |
Frequently asked questions
Does this SQL formatter run my query?+
No. The tool only rearranges the statement at the lexical and syntactic level; it never connects to a database and never inspects data. Pasting a production statement with real table names is safe because the text never leaves your browser.
Which SQL dialects are supported?+
MySQL, MariaDB, PostgreSQL, SQL Server (T-SQL), SQLite, BigQuery, Snowflake, and Spark SQL, among others. The dialect drives reserved-word detection and quoting rules, so choosing the right one gives you more accurate line breaks.
Why does the same query come out differently for different people on my team?+
Because three settings differ: indentation width, keyword case, and dialect. Agree on one combination, write it into your style guide, or better still run the same formatter in CI so everyone gets identical output.
Related tools
All toolsJSON Formatter
Format, minify, and validate JSON with line-and-column error reporting
JSON Validator
Validate JSON syntax and pinpoint the failing line and column
JSON Viewer
Explore JSON as a collapsible tree and read off access paths
JSON Escape / Unescape
Escape and unescape JSON strings
XML Formatter
Pretty-print or minify XML while checking that every tag is closed
YAML Formatter & Validator
Validate YAML syntax and normalize the indentation