Developer · Formatter
SQL formatter.
Beautify or minify SQL for standard SQL, PostgreSQL, MySQL and SQLite. Pick the keyword case, indent and comma position. Runs in your browser; your query is never uploaded.
Input
Output
Paste SQL, then press Format or Minify.
Worked example
This 20-line result is what the page produces for one PostgreSQL query typed on a single line (Load example fills it in). With UPPER keywords, 2-space indent and leading commas:
SELECT
u.id
, u.email
, count(o.id) AS orders
, sum(o.total) AS spend
FROM
users u
LEFT JOIN orders o ON o.user_id = u.id
WHERE
u.created_at >= '2026-01-01'
AND u.status IN ('active', 'trial')
GROUP BY
u.id
, u.email
HAVING
count(o.id) > 0
ORDER BY
spend DESC
LIMIT
20;
Minify turns the formatted version into one line: 291 bytes become 260, a 10.7% saving. SQL has little whitespace to remove, so the saving is modest. The main use of minifying is putting a query on one line in a config file, log line or string literal.
How it works
Format uses the open-source sql-formatter library, version 15.9.0, MIT licence, served from this site rather than a third-party CDN. It parses the query with a dialect-specific grammar, so PostgreSQL, MySQL and SQLite syntax (for example :: casts, backtick identifiers, ILIKE) is recognised. Choose Standard SQL if your dialect is not listed. If the library cannot parse the text it reports an error instead of guessing.
Comma position. The library always puts commas at the end of a line. For Leading, this page moves each line-ending comma to the start of the next line, using a scanner that skips string literals, quoted identifiers and comments so commas inside them are never moved. A comma that is followed by a comment line is left in place.
Minify is this page's own scanner. It removes comments, collapses runs of whitespace to one space, and removes the space around commas, semicolons and just inside parentheses. It never changes anything inside a quoted string or identifier. It keeps PostgreSQL dollar-quoted strings ($$...$$) and MySQL executable and hint comments (/*! ... */, /*+ ... */) because removing those changes what the query means. It also treats -- as a comment in MySQL only when followed by whitespace, and # as a comment only in MySQL, as that dialect defines.
Sources and as-of date (checked 2026-09-30):
sql-formatter on GitHub (library and supported dialects);
PostgreSQL: Lexical Structure (comments, nested block comments, dollar quoting);
MySQL 8.4: Comments (#, -- and executable comments);
SQLite: SQL Comment Syntax.
Frequently asked questions
Is my SQL uploaded anywhere?
No. Formatting and minifying run in your browser using JavaScript served from this site. Nothing you paste is sent to a server or stored.
Does formatting change what my query does?
It should not. Formatting changes whitespace and, if you choose, the case of keywords. Identifiers and strings are left as typed. Always review the result before running it on real data, and keep your original.
Does this validate my SQL?
No. A successful format means the text could be parsed by the formatter, not that the query is valid for your database, that the tables exist or that it will run. Only your database can tell you that.
Why did minify keep a comment?
Comments that start with /*! or /*+ are executable or optimizer-hint comments in MySQL, so they are kept on purpose.
Formatting only
This tool rearranges the text of a query. It does not execute SQL, check it against a schema or review it for safety. Nothing you type is stored or sent anywhere.