SQL Formatter and Minifier

Line breaks go in at SELECT, FROM, WHERE and friends, with indentation following bracket depth. Nothing here interprets what the statement means — only how it looks — so MySQL, PostgreSQL, and Oracle all work, and unfamiliar syntax comes out intact rather than mangled.

Indent

Pasted code never leaves your device. Everything runs in your browser; nothing is sent or stored anywhere. That is what makes it usable for internal config files and production queries.

Where the line breaks go

A new line starts before SELECT, FROM, WHERE, GROUP BY, HAVING, ORDER BY, LIMIT, the JOIN family, ON, AND, OR, INSERT INTO, VALUES, UPDATE, SET, DELETE FROM, UNION, WITH, and CREATE, ALTER and DROP TABLE. Because AND and OR get their own lines, a long WHERE clause ends up with one condition per line, and conditions stop hiding in the middle of a paragraph. Indentation follows bracket depth: a subquery steps in one level, and when a closing bracket opens a line, that line steps back out.

Uppercasing only touches the keywords that open a line

The uppercase option, on by default, changes only the keywords listed above. AS, DISTINCT, COUNT and column names stay as typed, so a result that looks half uppercased is working as intended. There is a price for not reading meaning: a column named set or limit written without quotes will get a line break in front of it, because it looks like the keyword. Wrap such names in double quotes or backticks and the formatter treats them as strings and leaves them alone.

What minifying removes

Runs of spaces and line breaks collapse to one space, spaces around brackets, commas and semicolons are dropped, and /* */ comments are deleted. A -- comment is deleted too, but one line break is kept in its place — the comment runs to the end of the line, and deleting it outright would glue the next line onto the previous one and produce a different statement. Anything inside quotes is kept exactly, including a quote written as ''. Use it for one-line log entries or for passing a query as a URL value.

Where a keyword means something else

Not reading meaning costs something wherever a word is used in another sense. The AND in BETWEEN 1 AND 10 joins no conditions, yet a line break lands before it; so do the OR in CREATE OR REPLACE, the ON in ON DELETE CASCADE and the WITH in WITH ROLLUP. The other way round, CASE … WHEN … END and a value list such as IN (1, 2, 3) never trigger a break, so they stay on one line however long they get.

Several statements, and where comments go

Statements joined by semicolons usually separate, since the next statement's first keyword starts a new line. A -- line comment stays at the end of the line it was attached to, and a /* */ comment is set aside as a placeholder and put back, so even the line breaks inside it survive — though a block comment that had a line to itself ends up attached to the previous line.

Frequently asked questions

Which databases are supported?

All of them, because the formatter never parses meaning. It splits on keywords and brackets only. The trade-off is that it cannot offer judgment calls like rewriting a join.

Does it break lines inside string literals?

No. Quoted strings and comments are carried across whole. A formatter that reacted to a keyword inside a string literal would be editing your data.

Are keywords inside quotes reformatted?

No. String contents are left alone; breaking a line at a 'FROM' that is a value would corrupt the query.

Does it uppercase keywords?

With "Uppercase keywords" on, only the keywords that start a new line (SELECT, FROM, WHERE, JOIN and the like) are uppercased. It is on by default; switch it off and your text is left as written. Either way it is convention, not syntax, so follow your team's rule. Column names and text inside string literals are never touched.

Every line after a certain point is indented one level.

There is an unclosed parenthesis. Indentation is decided by counting parentheses, so one opening parenthesis left over pushes every following line one level in. It would fail as a syntax error when run, so this makes it easier to find. Parentheses in strings and comments are not counted.

Does anything I paste get sent to a server?

No. Everything runs inside your browser and nothing is uploaded or stored. That is why you can use it on things you would not normally paste into a web page, like an internal config file or a production query. It also works with your network disconnected.