SQL formatter

Paste a query to lay it out neatly, one clause per line, for PostgreSQL, MySQL, SQLite, SQL Server, BigQuery, Snowflake and more. Choose upper- or lower-case keywords and your indent, or minify it onto one line.

Your SQL
Formatted
Loading the formatter…
Loading the formatter…⌘Enter format Shift⌘Enter minify

How to use it

Paste your SQL on the left and the formatted version appears on the right. Pick the dialect your database speaks from the list, then choose how keywords should look and how far to indent. Press ⌘ Enter to format and Shift ⌘ Enter to minify. Your settings are saved in the page link, so you can bookmark your team’s style.

If the formatter can’t make sense of the query, the problem is underlined in your SQL and explained in the status bar. Click “Show in input” to jump to it.

A worked example

A one-line query is hard to scan:

select u.id, u.email, count(o.id) as orders from users u left join orders o on o.user_id = u.id where u.created_at >= '2026-01-01' group by u.id, u.email order by orders desc;

Formatted for PostgreSQL with upper-case keywords and a 2-space indent, each clause gets its own line and each column its own row, so you can see at a glance what’s selected, joined and filtered:

SELECT
  u.id,
  u.email,
  COUNT(o.id) AS orders
FROM
  users u
  LEFT JOIN orders o ON o.user_id = u.id
WHERE
  u.created_at >= '2026-01-01'
GROUP BY
  u.id,
  u.email
ORDER BY
  orders DESC;

Minified, the same query goes back to one line with the extra spaces taken out: SELECT u.id,u.email,COUNT(o.id) AS orders FROM users u LEFT JOIN orders o ON o.user_id = u.id WHERE u.created_at >= '2026-01-01' GROUP BY u.id,u.email ORDER BY orders DESC;

What the formatter does

  • Puts each clause on its own line: SELECT, FROM, JOIN, WHERE, GROUP BY, ORDER BY and so on, with their contents indented underneath.
  • Lists one column per line, which makes diffs in code review much easier to read.
  • Indents subqueries and CTEs so nesting is visible.
  • Sets keyword case to UPPER, lower or as you typed it. Data types (VARCHAR, INT) and functions (COUNT, SUM) follow the same choice.
  • Leaves your data alone. String literals, quoted identifiers and comments are never changed.
  • Handles many statements separated by semicolons, with a blank line between each.

Dialects

DialectThings it understands
PostgreSQL$$ strings, :: casts, ->> JSON operators, RETURNING
MySQL / MariaDB`backtick` names, # comments, backslash escapes in strings
SQL Server (T-SQL)[bracket] names, TOP, @variables, GO
SQLiteIts keywords and ? and :name parameters
BigQuery`project.dataset.table` names, STRUCT and ARRAY types
Oracle PL/SQLBEGIN … END blocks, :bind variables

Snowflake, Redshift, DuckDB, ClickHouse, Spark, Hive, Trino and Db2 are in the list too. If yours isn’t, Standard SQL works for most everyday queries.

Minifying

Minify puts a query on one line, which is handy for logs, environment variables or pasting into code. Comments are taken out, except optimizer hints like /*+ INDEX(t idx) */ and MySQL’s /*! … */, which can change how the query runs. Strings keep their spaces exactly.

Common mistakes

  • The wrong dialect. Backticks are names in MySQL but errors in PostgreSQL. If you see an error on a query that works, check the dialect first.
  • Unclosed strings. An apostrophe inside a string must be doubled: 'it''s'. A single one starts a string that never ends.
  • Template placeholders. Placeholders like {{ table }} from a templating tool may confuse the formatter. Replace them with a plain name, format, then put them back.
  • Treating “formats cleanly” as “correct”. The formatter checks structure, not whether your tables and columns exist.

Comparing two versions of a query? Use the text diff tool after formatting both the same way. Working with query results? The JSON formatter and JSON to CSV converter help with exports.

Questions people ask

Is my SQL sent anywhere?
No. The formatter runs in your browser and nothing you paste leaves your device, so it’s safe for queries that mention real table names. Only your choice of dialect, case and indent goes in the page link, never the query itself.
Which dialect should I pick?
The database the query runs on. Dialects differ in how they quote names ("col" in PostgreSQL, `col` in MySQL, [col] in SQL Server), in their keywords and in special syntax like PostgreSQL’s $$ strings or :: casts. If the formatter reports an error on SQL you know works, try the dialect again: that’s the usual cause.
Does formatting change what my query does?
No. Only whitespace and the case of keywords change. Strings, quoted names and comments are kept exactly. It’s still worth running your tests after reformatting a large file, just as you would with any tool that rewrites code.
Should SQL keywords be upper case?
It’s a style choice, not a rule: SQL doesn’t care. Upper-case keywords (SELECT, FROM) stand out from table and column names, which is why many style guides use them. Many teams now prefer lower case because it’s quicker to type. Pick one and stick with it.
Why does it say there’s an error?
The formatter has to understand the structure of the query, so it stops at things like an unclosed bracket or string. Click “Show in input” to jump to the spot. It isn’t a full validator: a query can format cleanly and still fail on the database, for example if a table doesn’t exist.
↑↓ move↵ openesc close