SQL IN Clause Formatter
Make a dense query readable. The formatter uppercases the keywords, puts every clause on its own line, breaks a long WHERE IN list into one value per line and keeps subqueries intact, while string literals and comments are left exactly as you wrote them.
SQL query
Formatted SQL
Ready — paste some input or load the sample.
100% Client-Side · Privacy First. This tool runs entirely inside your browser. Nothing you type is uploaded, logged or sent to a server — you can even use it offline.
Overview
Long SQL queries are hard to read once they are written on one line, and the hardest part of reformatting them safely is not the layout but the data inside the query. A string literal may contain a comma, a semicolon or the word SELECT, and a naive reformatter will happily treat all of those as syntax and destroy the statement. This formatter masks string literals and comments before it does anything else, so only real SQL tokens are touched. After that it breaks the statement into clauses, puts every clause on its own line, indents the body, and expands an IN list so each value sits on its own line. Semicolons inside a literal never split the statement, and the keywords inside a literal are never uppercased. The result is a query you can actually read in a code review, without changing what it does.
How to use the sql in clause formatter
- 1Paste your SQL into the input panel.
- 2Read the reformatted statement in the output panel, especially around the string literals.
- 3Check the notes for the number of statements that were formatted.
- 4Copy it back into your editor or your query console.
- 5Run the statement in a transaction or a read only session first, so a formatting surprise cannot reach production data.
Cheat sheet
The syntax you will use most, and what each part does.
| Pattern | What it means |
|---|---|
SELECT, FROM, WHERE |
Each clause starts on a new line, with the body indented underneath it. |
IN (1,2,3) |
The list is expanded so each value is on its own line. |
a quoted literal |
A quoted literal is protected, so a comma inside it is never treated as a separator. |
comment markers in a literal |
Comment markers inside a string literal are not treated as comments. |
a = 1; b = 2 |
A semicolon outside a literal splits two statements, which are formatted separately. |
JOIN ... ON |
Join clauses are recognised as their own block, with the ON condition aligned. |
Common mistakes
A string literal is broken up.
The formatter masks quoted strings before it looks for commas, so a value with an apostrophe or a comma inside a literal is never touched.
The statement is split in the wrong place.
A semicolon inside a string literal does not split a statement, only a real one does. Check for an unterminated quote if the output looks truncated.
Keywords inside a literal are uppercased.
They are not, because the literal is masked before the keyword pass runs. A value of select stays exactly as written.
A comment ends up on the wrong line.
Comments are copied verbatim, so a trailing comment stays attached to the clause it was written next to. Move it onto its own line if the position matters.
Worked examples
A query with a literal
select id, name from users where id in (1,2,3) and status = 'active';
A formatted statement with the IN list expanded and the string literal preserved.
A literal that contains SQL keywords
select * from t where tag = 'select, from, where';
The literal is kept intact and the statement is not split at the comma or the semicolon inside it.
Frequently asked questions
Does it change the meaning of the query?
No. The formatter only changes whitespace and the case of keywords. String literals, comments and the order of the clauses stay exactly as they were, so the statement means the same thing before and after.
Are comments kept?
Yes. Both a line comment that starts with two dashes and a block comment between slash and star survive the formatting, including any SQL keywords that happen to be inside them.
Does it handle several statements?
Yes. A semicolon that is not inside a literal or a comment splits the input into separate statements, and each one is formatted on its own with a blank line between them.
Which dialect does it target?
The formatting is dialect neutral, so it works with PostgreSQL, MySQL, SQLite and SQL Server. The keywords it recognises are the ones that the four of them share.
How is a long IN list handled?
The list is expanded so that every value sits on its own line, indented under the IN keyword. A list of three hundred values becomes three hundred lines, which diffs cleanly and reads far better than one enormous line.
What happens to a subquery?
A parenthesis that opens a nested expression keeps its contents together and is kept on one logical level, so a subquery in a WHERE clause stays recognisable instead of being flattened into the outer query.
Are the keywords uppercased inside a string?
No. A literal such as "select from where" is detected first and skipped, so it comes out of the formatter unchanged. That was the single most damaging bug in older versions of this tool.
Can I use the output in a version control diff?
Yes, and that is one of the main reasons to format a query at all. A reformatted statement produces a stable diff, so a change in the logic shows up instead of a wall of shifted whitespace.
Does it re-indent my subqueries?
It keeps the nesting of a parenthesised expression together and indents the result relative to the clause, so a subquery stays visually separated from the outer query.
What about a semicolon inside a string?
It is not treated as a statement separator, because the string literal is detected before the split happens. A literal such as "a;b" therefore does not cut the statement in half.
Can I format a statement that uses a CTE?
Yes, a common table expression is treated as a clause and put on its own line, with the rest of the statement following it.