SQL Formatter

Pretty-print or minify SQL with multi-dialect support.

About SQL Formatter

SQL Formatter pretty-prints or minifies a SQL query with dialect-aware parsing for the major engines: PostgreSQL, MySQL, SQLite, BigQuery, MS SQL Server (T-SQL), Oracle, Redshift, Snowflake, and ANSI standard SQL. Pick the dialect that matches your database; the formatter respects engine-specific keywords (`LATERAL`, `QUALIFY`, `CROSS APPLY`, `MERGE`, etc.) and keeps comments and string literals untouched.

Reach for it when an unformatted query has gone unreadable: a one-line query copied from a log line, a generated query from an ORM, or a hand-written query that has accumulated diff noise. The formatted output indents `SELECT` columns, aligns `JOIN` clauses, breaks `WHERE` conditions across lines, and uppercases keywords — the canonical layout most teams expect for code review. Minify runs the inverse transform when you need a single-line query for embedding in a script or environment variable.

Examples

Input
select id, name from users u left join orders o on o.user_id = u.id where u.active = true and o.total > 100
Output
SELECT
  id,
  name
FROM
  users u
  LEFT JOIN orders o ON o.user_id = u.id
WHERE
  u.active = TRUE
  AND o.total > 100

Pretty-print with PostgreSQL dialect. Keywords uppercased, columns indented, JOIN aligned, WHERE conditions broken across lines.

Frequently asked questions

Which dialect should I pick?

The one your database uses, so engine-specific keywords (`QUALIFY` for BigQuery / Snowflake, `MERGE` for SQL Server, `LIMIT … OFFSET` ordering for PostgreSQL vs MySQL) are recognised and not mistakenly broken across lines as identifiers. Standard SQL is a safe fallback for portable queries.

Does it execute the query?

No. The formatter parses and re-emits the SQL text — it does not connect to a database. Nothing is sent to a server, and the formatted output is identical in semantics to the input.

Will it preserve my comments?

Yes. Both `--` line comments and `/* … */` block comments are kept in their relative positions, so a code-review-ready query keeps its annotations intact.

Can it format dynamic SQL with parameters like `$1` or `:name`?

Yes. Common parameter placeholders (`$1`, `?`, `:name`, `@param`, `${name}`) are treated as values and survive formatting unchanged.