Beautify or minify SQL for PostgreSQL, MySQL, SQL Server, Oracle, BigQuery and 15 more dialects, errors by line
Turn a one-line query from a log or an ORM into SQL you can read, or minify it back onto one line.
How to use it
Paste SQL on the left, or open a .sql file. Scripts with many statements are fine. Pick the dialect your database speaks, the indent and how keywords are written. Options holds the rest: the case of names, data types and functions, a tabular layout, commas at the start of the line, short lists on one line, comments removed. Copy or download the result, as SQL or as a string for Java, C#, PHP, Python, JavaScript or Go. SQL it can’t read gets the line and column, marked in your text.
Examples
A query from a log
select id, name from users where active = 1 and role in ('admin', 'dev') order by nameSELECT
id,
name
FROM
users
WHERE
active = 1
AND role IN ('admin', 'dev')
ORDER BY
nameMinify, comments out, strings kept
SELECT id,
note -- the customer's note
FROM orders
WHERE note = 'two spaces';SELECT id,note FROM orders WHERE note = 'two spaces';
Optimizer hints such as /*+ INDEX(o) */ stay, since they change how the query runs.
What formatting changes
Why the dialect matters
PostgreSQL, MySQL, MariaDB, SQLite, SQL Server (T-SQL), Oracle PL/SQL BigQuery, Snowflake, Redshift, ClickHouse, DuckDB, Spark SQL, Hive, Trino / Presto Db2, Db2 for i, N1QL (Couchbase), SingleStore, TiDB, and standard SQL
Questions
- Does it check that my SQL is valid?
Only that it can be read: a missing bracket or a word where it can’t stand is named with its line and column. It doesn’t know your tables, so a wrong column name or a type error passes. - Can I get the SQL as a string for my code?
Yes: Options, Output. Java and Go get one quoted line per SQL line joined with +, C# a verbatim @"…" string, PHP a single-quoted string, Python a triple-quoted string and JavaScript a template literal. Quotes, backslashes and ${ are escaped so the string holds the SQL exactly. - Can commas start the line?
Yes: Options, Commas, Start the line puts each list’s comma before the next item (a comma followed by a comment stays where it is, or the comment would swallow it). Lists on one line joins short lists of columns or values up to the width. - Why did a query with ? or :name placeholders format oddly?
Placeholders differ by driver. Pick the dialect your code talks to; PostgreSQL reads $1, most others ? and :name. - Is my SQL uploaded?
No. Everything runs in your browser, so your SQL stays on your device. Nothing you paste is uploaded unless you share a result, which is locked with your password first. Scripts and dumps can hold customer data or passwords, and the page warns you if it spots a key.