SQL formatter

Format SQL with consistent keyword casing and indentation.

FreeRuns in your browserNo signupUpdated 2026-10-29

Pick the dialect your database uses so quoting, casts and functions are recognised. Identifiers and string values are never changed.

Lines

21

In the formatted output

Status

Formatted

PostgreSQL rules

query.sql
SELECT
  c.id,
  c.name,
  COUNT(o.id) AS orders,
  SUM(o.total) AS revenue
FROM
  customers c
  LEFT JOIN orders o ON o.customer_id = c.id
  AND o.status = 'paid'
WHERE
  c.created_at >= '2026-01-01'
  AND c.country IN ('IN', 'AE', 'GB')
GROUP BY
  c.id,
  c.name
HAVING
  SUM(o.total) > 1000
ORDER BY
  revenue DESC
LIMIT
  20;

About this tool

How it works and how to read the result.

Need this done for you?

Web app & SaaS development

SaaS products and web apps, from first version to scale.

See the service

What it does

A SQL formatter rewrites a query so that each clause sits on its own line, keywords share one case and nested conditions are indented. Paste a query copied from a log, an ORM debug output or a colleague's message, pick the dialect your database uses, and the readable version appears on the right. Keyword case, indent width and dialect are configurable, and there is a collapse option for the opposite job of squeezing a query onto one line for a config file or a log search. Nothing is sent anywhere.

How to use it

  1. Paste the SQL from your editor, a log or an ORM's debug output. Multiple statements separated by semicolons are fine.
  2. Choose the dialect: PostgreSQL, MySQL, SQLite, SQL Server, BigQuery, Snowflake and others.
  3. Set keyword case and indent size to match your team's style.
  4. Copy the result or download it as a .sql file. Tick "Collapse to a single line" when you need the compact form instead.

How to read the result

The sample is a 300-character query on one line. Formatted for PostgreSQL with uppercase keywords it becomes 21 lines. SELECT, FROM, LEFT JOIN, WHERE, GROUP BY, HAVING, ORDER BY and LIMIT each start a line, the selected columns are listed one per line under SELECT, and the two conditions in the WHERE clause are indented with AND at the start of the second line.

That layout makes two things easy to spot. First, the join has an extra condition on order status, which is why unpaid orders are excluded before grouping rather than after. Second, the HAVING clause filters on the summed revenue, so customers below 1,000 drop out after aggregation. Both would be easy to miss in the one-line version.

The status badge turns red on a parse error and the hint shows the first line of the message. Identifiers, string literals and numbers are never changed, so a formatted query returns exactly the same rows as the original.

Readable queries are how we keep web app back ends maintainable. For the environment variables that hold the connection string, use the .env to JSON converter.

Questions

Frequently asked.

Does the dialect setting matter?

Yes, for anything beyond basic SELECT statements. PostgreSQL casts with double colons, SQL Server brackets and TOP, MySQL backticks and BigQuery's backtick-quoted project paths are all parsed differently. Picking the wrong dialect usually produces a parse error or odd line breaks rather than silently wrong SQL.

Should keywords be uppercase?

It is a convention, not a rule; databases do not care. Uppercase keywords make the structure stand out from table and column names, which is why most style guides and this formatter's default use it. The important thing is consistency within a codebase, so match what your team already does.

Why do I get a parse error?

The formatter builds a syntax tree, so it needs valid SQL for the chosen dialect. Common causes are a missing comma between columns, an unbalanced bracket, placeholder syntax from an ORM, or a dialect mismatch. Fix the statement or switch dialects; the error message names the token where parsing stopped.

Your next move

Like what you see? Tell us about it.

A process that takes too long, a website that undersells you, or an idea ready to take shape. Tell us where you are and we will suggest a useful next step.

India · Working with clients worldwide

We reply within a working day. No spam, ever.