Skip to content
snowkitDev

Squeeze SQL onto one line

Paste a query and get it back on a single line, with comments and spare spaces gone and every string left exactly as written.

SQL formatter

Paste a query and the clean version appears as you type.

Keywords
Result

            

Paste a query from a log, an ORM or a colleague and get it back neatly indented, with each clause on its own line, subqueries nested and keywords in the case you like. Or go the other way and squeeze it onto one line. Your queries stay on this device. It is free.

How to format SQL, step by step

  1. Paste your query into the SQL box. The clean version appears as you type.
  2. Choose Format or Minify.
  3. Pick the Keywords case (UPPER, lower or As typed) and the Indent (2 spaces, 4 spaces or Tab).
  4. Turn on One column per line if you want long column lists spread out.
  5. Press Copy SQL, or Download .sql.

What gets formatted

SELECT, FROM, WHERE, GROUP BY, HAVING, ORDER BY and LIMIT each start a new line, with their contents indented underneath. Every kind of JOIN lines up under FROM, AND and OR conditions get their own lines, CASE expressions are laid out WHEN by WHEN, and subqueries and WITH clauses are indented as blocks. INSERT, UPDATE, DELETE and CREATE TABLE work too, with one column definition per line.

Safe for any database

The formatter only changes whitespace and keyword case. Strings, quoted names in double quotes, backticks or square brackets, comments, placeholders like $1, ? and :name, and Postgres casts like ::int are left exactly as written, so it works for PostgreSQL, MySQL, SQLite, SQL Server, Oracle, BigQuery and Snowflake queries alike.

When to minify

Minify removes comments and extra spaces to put a query on a single line, which is handy for log searches, environment variables, JSON payloads or code that builds a query string. Spaces inside strings are never touched.

Why format your SQL

  • Readable queries are easier to review and debug.
  • Consistent style helps teams and makes code reviews quicker.
  • You can spot a missing join condition or a misplaced bracket sooner.
  • Clean examples are easier to share in tickets, documentation and questions.

To run a query on a spreadsheet or a database file, use the SQL playground. For JSON, try JSON tools, and for other code, the code formatter.

Questions

Does it check that my SQL is correct?

No. It tidies the layout but does not run the query or check it against a database.

Is my query sent anywhere?

No. It is formatted in your browser.

Can I use it for stored procedures?

It handles common statements. Very database-specific code may keep some of your own layout.

Where to next

Carry on with what you just made, still on your device.

More from Snowkit