SQL Formatter

Paste a query, pick your dialect, get readable SQL. Beautify one-line queries from logs and ORMs, standardise keyword case, and tidy migrations before review. It all runs in your browser.

Formatted · PostgreSQL
Sends only this query to an AI model. Formatting itself never leaves your browser.

What the formatter does to your SQL

A SQL beautifier rewrites only the layout of a query. It tokenises the text for the dialect you choose, then puts each major clause (SELECT, FROM, JOIN, WHERE, GROUP BY, ORDER BY) at the left margin, one selected column per line, and indents subqueries and CASE expressions one level deeper. String literals, quoted identifiers and comments are left untouched, so the formatted query is guaranteed to mean the same thing.

Choosing options your team will agree on

  • Keyword case. Uppercase keywords are the long-standing convention in vendor documentation; lowercase is popular in dbt projects and modern style guides. Pick one and apply it everywhere.
  • Leading commas make it easy to comment out the last column and produce cleaner diffs; trailing commas read more like prose. Both are valid.
  • AND / OR at the start of the line lines up the conditions of a WHERE clause so you can scan them vertically.

Dialect matters

MySQL quotes identifiers with backticks, SQL Server with square brackets, PostgreSQL with double quotes and supports :: casts and $$ strings, BigQuery allows dashes in project names. Choosing the wrong dialect is the most common reason a formatter fails, so set it before you paste.

Once the query reads well, check that it parses with the SQL validator, or shrink it back to one line for a config file with the SQL minifier. If you are designing the tables behind the query, paste the CREATE TABLE statements into the ER diagram generator.

The rest of the toolkit

Everything runs in your browser, with no signup.

Questions

Is my SQL sent to a server?

No. Formatting runs entirely in your browser with the open-source sql-formatter library. Nothing leaves your device unless you press “Explain with AI”, which sends only the query text to the AI model.

Which SQL dialects are supported?

Standard SQL, MySQL, MariaDB, PostgreSQL, SQL Server (T-SQL), Oracle PL/SQL, SQLite, BigQuery, Snowflake, Amazon Redshift, Spark SQL, DB2, Trino/Presto and DuckDB. Picking the right dialect matters for things like backtick identifiers, :: casts, @variables and dollar-quoted strings.

Does formatting change what my query does?

No. The formatter only changes whitespace, line breaks and the case of keywords. Identifiers, string literals and comments are kept exactly as written, so the formatted query returns the same result.

Why did the formatter fail on my query?

Usually the dialect is wrong (for example T-SQL square-bracket identifiers under PostgreSQL) or the query uses template placeholders like {{name}}. Switch the dialect or replace placeholders, then format again. The SQL validator gives the exact line and column of a syntax error.

Should SQL keywords be uppercase?

SQL is case-insensitive for keywords, so it is a style choice. Uppercase keywords remain the most common convention in documentation and style guides such as Simon Holywell’s SQL Style Guide, because they separate the language from your table and column names.

Can I format many statements at once?

Yes. Paste a whole migration or script; statements separated by semicolons are formatted one after another, with the number of blank lines between them set by “Lines between queries”.