“This query is too dense to read…”

A massive SQL query flattened onto a single line by a production system. A stored procedure where nested JOINs pile up like a maze. “Where does this condition branch?” — staring at a wall of SQL like that is a familiar frustration.

The SQL Formatter reformats pasted SQL entirely inside your browser, so even sensitive production queries never leave your machine.

SQL Formatter: making queries readable, and why dialect selection matters

Before / after

select users.id,users.name,count(orders.id) from users left join orders on users.id=orders.user_id where users.deleted_at is null group by users.id,users.name order by users.id desc;
SELECT
  users.id,
  users.name,
  COUNT(orders.id)
FROM users
LEFT JOIN orders ON users.id = orders.user_id
WHERE users.deleted_at IS NULL
GROUP BY
  users.id,
  users.name
ORDER BY users.id DESC;

Just cleaning up the layout makes missing conditions, JOIN direction, and aggregation granularity much easier to spot.

Why dialect selection is mandatory, not optional

A SQL formatter has to tokenize and understand the syntax before it can decide where to break lines and indent. That means dialect-specific extensions directly affect whether formatting succeeds at all.

Dialect difference Standard SQL MySQL PostgreSQL BigQuery
Identifier quoting "name" `name` "name" `project.dataset.table`
String concatenation || CONCAT() || ||
LIMIT syntax LIMIT n LIMIT n LIMIT n OFFSET m LIMIT n
Arrays/structs non-standard unsupported ARRAY[...] STRUCT<...>

Parse MySQL’s backtick-quoted identifiers as Standard SQL, for instance, and token boundaries can shift enough to break the formatting entirely. Most “the formatter output looks wrong” reports trace back to picking the wrong dialect. The tool supports PostgreSQL, MySQL, MariaDB, SQL Server, BigQuery, and more — match it to the database you’re actually working with, and re-formatting happens automatically whenever you switch dialects.

Formatting options, templates and stored scripts

The SQL Formatter has eleven options that shape the output.

Option Choices Effect
Keyword case Preserve / Upper / Lower for example, turning select into SELECT
Indent 2 spaces / 4 spaces / Tab match your team’s convention
AND / OR position Before / After putting them at the start of the line keeps the diff small when you add or remove a condition
Maximum line width Narrow (30) / 50 / Wide (80) the smaller it is, the taller the output, and the more often lines inside parentheses break
Function case Preserve / Upper / Lower aligns COUNT(*) and count(*); set separately from the keyword case
Data type case Preserve / Upper / Lower aligns VARCHAR(10) and varchar(10)
Identifier case (tables, columns) Preserve / Upper / Lower quoted identifiers ("Name", `name`) are left alone
Keyword alignment Standard / Left / Right left and right (river style) line up SELECT, FROM and WHERE vertically and start the contents at the same position
Operator spacing With spaces / Compact compact output closes the gaps, as in a=1 and a+b
Semicolon End of line / Own line with its own line, a line containing only ; follows each statement
Blank lines between queries 1 / 2 / 3 the number of blank lines between statements when formatting several

When your SQL looks like another dialect (ON CONFLICT, TOP, AUTO_INCREMENT and so on), the tool says “this looks like PostgreSQL syntax” and offers to switch. It never switches on its own, and says nothing when the SQL only uses syntax common to all dialects.

Real-world SQL also contains constructs that would be syntax errors as they stand. These can be formatted without breaking their contents:

  • Template variables: dbt and Jinja {{ ref('orders') }}, {% if … %} and {# … #}, and shell/JS ${var}, are treated as a single unit.
  • SQL Server GO: with the SQL Server (T-SQL) dialect selected, a line containing only GO splits the script into batches, and each batch is formatted separately. A go inside a string or comment isn’t treated as a separator.
  • MySQL DELIMITER: scripts containing lines such as DELIMITER // are split into statements by each delimiter before formatting, so // is never broken apart.

The opposite “minify” button squeezes whitespace, line breaks and comments into a single line. The contents of string literals are left unchanged (comments are removed). Use it when you want to embed a query on one line in a log or a config file.

What to check during SQL review

Once formatted, a few extra checks raise the quality of the review itself.

  • Does the WHERE clause do what you think it does?
  • Are any JOIN conditions missing?
  • Is the choice between LEFT JOIN and INNER JOIN correct? (See SQL JOIN Types: Complete Reference for the full breakdown.)
  • Is the GROUP BY granularity what you expect?
  • Are ORDER BY / LIMIT present where they’re needed?
  • Are subqueries and CTEs each doing one clear job?

SQL pulled from logs tends to have every placeholder expanded, making it especially long. Formatting before reading can cut investigation time substantially.

Formatting does more than improve appearance

The real payoff isn’t cosmetic — it shows up in three places:

  1. Early syntax error detection — a parse failure means something is broken; it’s a free sanity check before you run the query
  2. Stable diffs — with a fixed formatting rule, a query change’s diff reflects only the meaningful edit
  3. Decoding machine-generated SQL — a single-line query an ORM spat out only becomes legible once formatted

The first point is easy to overlook: mismatched parentheses or a missing comma will surface as a formatting failure, catching mistakes before you ever execute the query.

Cleaning up, embedding, and rewriting for another database

Besides formatting, the SQL Formatter can tidy pasted SQL, embed it in code, and rewrite it for another database.

Clean up and embed

  • Remove comments: strips -- and /* */. MySQL’s /*! … */ and optimizer hints /*+ … */ are kept because they change behavior
  • Switch identifier quotes: between MySQL `x`, PostgreSQL / SQLite "x" and SQL Server [x]. Quotes are only removed when the name is lowercase letters, digits and _, and not a reserved word
  • Wrap as a string for code: JavaScript (template literal), Python (triple quotes), Java (text block), Go, PHP, C# or JSON
  • Extract SQL from a code string: reads concatenations like "SELECT … " + "FROM …" and \n escapes and gives the SQL back, so a query copied from a log or source file can go straight into formatting

Rewriting for another database

Between MySQL, PostgreSQL, SQLite and SQL Server it rewrites what can be fixed mechanically. Strings, comments and quoted identifiers are never touched.

Item Example
Identifier quotes `id` → "id" → [id]
Row limits LIMIT 10, 5 → LIMIT 5 OFFSET 10; to SQL Server, TOP (n) / OFFSET … FETCH
NULL replacement IFNULL(a, 0), ISNULL(a, 0) ⇄ COALESCE(a, 0)
Current time NOW() ⇄ GETDATE() ⇄ CURRENT_TIMESTAMP
String aggregation GROUP_CONCAT(x SEPARATOR ',') ⇄ STRING_AGG(x, ',')
Casts a::int → CAST(a AS int)
Types and auto-increment (CREATE TABLE) AUTO_INCREMENT ⇄ SERIAL ⇄ IDENTITY(1,1), TINYINT(1) → BOOLEAN, DATETIME → TIMESTAMP, …

Anything that cannot be fixed mechanically is left alone and listed under “Check by hand”: ILIKE (changed to LIKE, with a note about case sensitivity), || (means OR in MySQL), RETURNING, upserts (ON CONFLICT vs ON DUPLICATE KEY UPDATE), GROUP_CONCAT with ORDER BY, and MySQL backslash escapes. The result is a starting point. Dialects differ in many subtle ways, so always test it on the real database.

FAQ

Does it support MySQL and PostgreSQL SQL?

Yes — Standard SQL, MySQL, PostgreSQL, MariaDB, SQL Server, and BigQuery are all supported. If your SQL uses dialect-specific syntax, double-check it before execution regardless.

Does formatting change what the SQL does?

No. Formatting only adjusts whitespace, line breaks, indentation, and keyword casing — the query’s meaning (its result) doesn’t change. Still, always confirm the formatted version matches your intent before running it.

What happens if I pick the wrong dialect?

Identifier quoting and keyword interpretation can shift, leading to broken indentation or unexpected line breaks. If formatting output looks wrong, check the dialect selection first.

Is it safe to paste SQL containing sensitive data?

Yes. Formatting happens entirely in your browser with no network calls — table and column names never leave your machine.

Can I convert MySQL SQL for PostgreSQL or SQL Server?

Yes for the mechanical parts: quotes, LIMIT, IFNULL / COALESCE, NOW(), GROUP_CONCAT / STRING_AGG, :: casts, and CREATE TABLE types and AUTO_INCREMENT. Things whose meaning changes, such as ILIKE, ||, upserts and RETURNING, are not rewritten; they are listed as items to check by hand. The result is not guaranteed to behave identically, so test it on the real database before running it.

Summary

  • The formatter itself is a one-line delegation to a library, but dialect selection is the parameter that actually determines the result
  • A single identifier-quoting difference can change how the query parses — match the dialect to your actual database
  • Formatting isn’t just cosmetic: it catches syntax errors early, stabilizes diffs, and decodes machine-generated SQL

Next time you pull a query out of a log, give it a pass through the formatter first.