# SQL Formatter > Free in-browser tool that formats messy SQL into readable SQL, with dialect, keyword case and indent controls, a minify mode, and structural checks for unbalanced parentheses, unclosed strings, and joins without a condition. Independent tool, not affiliated with any database vendor. Updated 2026-11-08. Full page: https://lab.awaara.cn/sql-formatter/ ## What it does - Formats SQL pasted into the page: each major clause (SELECT, FROM, WHERE, GROUP BY, ORDER BY, and the rest) starts a new line, SELECT, GROUP BY, and ORDER BY lists get one item per line, and subqueries, CASE branches, and parenthesised groups indent one level. - Dialects: Standard SQL, PostgreSQL, MySQL, MariaDB, SQLite, SQL Server (T-SQL), Oracle (PL/SQL), BigQuery, Snowflake. The dialect changes which words count as keywords and how quoting is read. MySQL and MariaDB read double quotes as strings and use backticks for names; the other dialects read double quotes as names. - Keyword case: UPPERCASE, lowercase, or as typed. It applies only to recognised keywords. Names, type names the formatter does not list, and function names keep the case typed. A column called name stays name, and a type called jsonb stays jsonb. - Indent: 2 spaces, 4 spaces, or a tab. - Minify: collapses the query to one line and removes line and block comments. Format mode keeps comments where they are. - Strip log prefixes: removes a leading timestamp and log level from each line, such as "2026-11-08 10:23:11 INFO", and reports how many lines were cleaned. - Copy the result or download it as a .sql file. Input is capped at 100,000 characters; longer input is cut at that point and the result says so. - Everything runs locally in the browser. Nothing is sent to a server; the page works offline once loaded. ## What it checks - Unbalanced parentheses: an opening parenthesis with no close is reported with the line where it opens; an extra closing parenthesis is reported the same way. - Unclosed strings: a string or quoted name that never closes stops the format, and the error names the line. - Joins without a condition: a JOIN with no ON or USING after it is flagged. Without a condition, a join pairs every row with every row. CROSS JOIN is the exception. - Literal check: after formatting, the page reads its own output back and compares every string, quoted name, number, and parameter with the input. If anything changed, the original is shown instead, with a warning. - Input that contains no SQL keyword at all is refused with a plain message instead of being "formatted". - It does not check column names, table names, or types, and it never runs the query. A query can format cleanly and still fail against a real database. ## What formatting changes, and what it never changes - Changes: line breaks, indentation, and keyword case when asked. - Never changes: strings, quoted names, numbers, and parameters. A string that contains the words "select * from" is copied exactly and never reflowed. - A parenthesised group stays on one line when it is short, and breaks across lines when it holds a subquery or runs long. A CASE expression breaks across lines: WHEN and ELSE each start a line, and END lines up with CASE. - Procedural code passes through: the body of a PL/pgSQL function or a T-SQL BEGIN...END block is copied as-is and may not re-indent beyond the surrounding statement. Dollar-quoted bodies are treated as one string and never split. ## Code snippets (from the page) - Python, with sqlparse: import sqlparse, then sqlparse.format(sql, reindent=True, keyword_case="upper"). - JavaScript, with sql-formatter: import { format } from "sql-formatter", then format(sql, { language: "postgresql", keywordCase: "upper" }). - Shell, with the sqlformat command: sqlformat --reindent --keywords upper query.sql > formatted.sql. ## Sources - PostgreSQL documentation, SELECT: https://www.postgresql.org/docs/current/sql-select.html - MySQL documentation, SELECT Statement: https://dev.mysql.com/doc/refman/8.4/en/select.html - SQLite documentation, SELECT: https://www.sqlite.org/lang_select.html - sqlparse documentation: https://sqlparse.readthedocs.io/ - sql-formatter on npm: https://www.npmjs.com/package/sql-formatter