Skip to content
Sealpaste

Delete all recent work?

This removes the 0 items saved in this browser. Your settings stay.

Stop saving recent work?

New work won't be saved in this browser. The 0 items already saved can stay or go.

SQL Formatter

SQL

Paste SQL, or

CtrlV paste · Ctrl↵ run now

Formatted SQL
Ready
Ln 1, Col 1
Runs in your browser. Nothing you paste is uploaded unless you share it.

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

  1. Paste SQL on the left, or open a .sql file. Scripts with many statements are fine.
  2. 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.
  3. 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

Input
select id, name from users where active = 1 and role in ('admin', 'dev') order by name
Result
SELECT
  id,
  name
FROM
  users
WHERE
  active = 1
  AND role IN ('admin', 'dev')
ORDER BY
  name

Minify, comments out, strings kept

Input
SELECT id,
       note -- the customer's note
FROM orders
WHERE note = 'two  spaces';
Result
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

Line breaks and indents between clauses, and the case of keywords if you choose UPPER or lower. Strings, numbers and comments stay exactly as written, so the query does the same thing. Names, data types and functions change case only if you choose it under Options; a name in quotes keeps its case.

A script is formatted statement by statement, cut at each “;” outside strings and comments. A single statement over 300 KB is left as written, with a note: formatting it would need too much memory.

Why the dialect matters

Databases quote and comment differently: MySQL uses `backticks` and # comments and needs a space after -- for a comment (5--2 is 5 minus -2), SQL Server and SQLite [brackets], PostgreSQL $$dollar-quoted$$ strings and ::casts. Pick yours so these are read as one piece, not split or re-spaced.

  • 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.

Related tools