Pretty-print messy SQL with tidy clauses and keywords.
A password or API key in a quoted value triggers a warning so it is not copied into a shareable gist next.
▸ More about
Uses of SQL formatting
- Cleaning a one-line query copied from an application log
- Making a long JOIN readable before a code review
- Checking a query from a ticket without pasting it into an upload site
SQL formatting pitfalls
- Pasting a query that still contains a live password into an online formatter that uploads text
- Expecting the formatter to rewrite or optimise the query plan
SQL formatting questions(8)
What does the SQL Formatter change?
Only layout. Keywords are uppercased, major clauses start on their own line, and nested lists inside parentheses are indented by two spaces. String literals, comments, numbers and identifiers stay exactly as you typed them, including escaped quotes like O''Brien.
Which SQL dialects does it understand?
The keyword list covers everyday Postgres, MySQL and SQLite: SELECT, JOIN variants, GROUP BY, ORDER BY, WITH, RETURNING, dollar-quoted strings, and the usual aggregates. Exotic vendor extensions are treated as ordinary identifiers and left alone, which is safe for readability.
Is my query sent to a server?
No. Formatting runs entirely in your browser. Nothing leaves this tab, nothing is stored remotely, and the page keeps working after you disconnect. That is the point of a formatter you can use on production queries.
Why should I avoid pasting queries with credentials into upload sites?
Many online formatters post your text to a server so they can run a library there. A query that still contains a password, API key or connection string then sits in that service's logs. Prefer a browser-only tool, and rotate any secret that has already been pasted elsewhere.
What happens if a quote is missing?
The formatter stops and reports an unclosed single-quoted, double-quoted or backtick string. Fix the quote and try again. It does not guess where the string should have ended.
Does it minify SQL as well?
This page pretty-prints. To shrink a query for a log line, start from the formatted output and join lines yourself, or use a dedicated minifier later. Pretty-print first so you can see what you are about to compress.
Will formatting change how my query runs?
No. Whitespace and keyword case are insignificant in SQL. The data in string literals and the spelling of identifiers are preserved, so the query means the same thing after formatting.
What about comments?
Line comments that start with -- and block comments between /* and */ are kept on their own lines. They are never deleted, because a formatter that drops comments is unsafe for production SQL.