SQL Formatter
Beautify SQL/SOQL, visualize EXPLAIN plans, and save named snippets.
Parse error: Unexpected ":30 AND Em" at line 1 column 82. This likely happens because you're using the default "sql" dialect. If possible, please select a more specific dialect (like sqlite, postgresql, etc).
About SQL Formatter
Re-indent, normalise keyword case, and break long SQL statements into a readable shape. Paste a one-line query pulled from a log, a dense statement copied out of a stored procedure, or a generated query from an ORM — the formatter restructures it so you can actually read what it's doing. Multiple dialects are supported so vendor-specific syntax stays intact.
What this tool does
- Pretty-print — clauses on their own lines, columns aligned, sub-selects indented.
- Keyword case — pick UPPER, lower, or preserve.
- Indent width — 2 or 4 spaces, or tabs, configurable.
- Dialect-aware — recognises PostgreSQL, MySQL, T-SQL, Oracle, BigQuery, Snowflake, and others so vendor-specific keywords format correctly.
When does SQL formatting matter?
Whenever you have to read SQL someone else wrote — a query in a stack trace, a migration file, a generated statement from an ORM, a snippet pasted into a ticket. A 600-character single-line query is unreadable; the same query broken across 30 lines with consistent indentation reveals its structure in seconds. Formatting also matters for diff reviews — two queries that differ only in whitespace produce a giant useless diff, while two consistently-formatted queries produce a diff that highlights the actual logic change. Many teams run a formatter as a pre-commit hook on .sql files for exactly this reason. Do not paste production credentials or live data into queries on this page; use placeholders.
Pipeline
Output from this tool can be sent directly to:
- CSV to SQL — generate
INSERTstatements from a CSV, then format the result for readability. - SOQL Query Builder — build Salesforce-flavoured queries with proper relationship traversal.
Privacy
Queries are formatted in your browser. Nothing is sent to a server. Read our privacy policy.
Frequently asked
- Which SQL dialects are supported?
- Standard SQL plus the major vendor dialects: PostgreSQL, MySQL/MariaDB, SQLite, MS SQL Server (T-SQL), Oracle PL/SQL, BigQuery, Redshift, Snowflake, Db2, and Spark SQL. Pick the dialect from the dropdown so the formatter recognises dialect-specific keywords (`MERGE`, `LATERAL`, `OVER`, `QUALIFY`, window-function syntax, etc.) and indents them correctly. The default is generic SQL, which works for the most common DML and DDL.
- Does it support SOQL?
- Partial support — SOQL shares a lot of syntax with SQL (`SELECT … FROM … WHERE … ORDER BY …`) so most queries format cleanly with the generic dialect. SOQL-specific constructs like relationship traversal (`SELECT Account.Name FROM Contact`), subqueries on child relationships, `WITH SECURITY_ENFORCED`, and `TYPEOF` may not indent ideally. For SOQL specifically, the SOQL Builder linked below is the right tool.
- Will it correct my SQL?
- No — the formatter is a pure pretty-printer. It re-indents and re-cases keywords, but it doesn't validate, optimise, or rewrite your query. A typo in a column name, a missing comma, a join condition that returns a Cartesian product — none of that gets flagged. If the input is unparseable, the formatter will return the original text unchanged or raise a clear error. Run the formatted query against your database to verify correctness.