Pretty print SQL queries for PostgreSQL, MySQL, and SQLite
Long single-line queries pulled from application logs or ORM debuggers hide join conditions and nested filters. Using a private SQL beautifier online turns tangled strings into scannable, clause-per-line blocks you can review in a pull request or run safely in a database console.
Indented subqueries, CTEs, and multi-line JOINs
In Format mode, the lexer scans up to 3 words ahead to align multi-word clauses such as SELECT DISTINCT, LEFT JOIN, GROUP BY, HAVING, ORDER BY, ON CONFLICT, and WITH RECURSIVE on fresh lines. Column lists after SELECT, GROUP BY, ORDER BY, SET, and VALUES break after every comma so each field sits at a consistent indent level.
Parentheses containing nested SELECT or WITH subqueries increase indentation automatically and align the closing parenthesis back to the outer block, following standard clause structure in the SQLite SELECT Syntax Documentation. Function calls such as count(o.id) or coalesce(a, b) stay compact on one line without extra inner line breaks. After running a query and exporting tabular rows, you can convert query result CSV exports into JSON for downstream API testing.
Choosing 2 spaces, 4 spaces, or Tabs with keyword casing
Under Mode, Format unlocks two layout controls: Indent (2 spaces, 4 spaces, or Tabs) and Uppercase keywords. Leaving Uppercase keywords checked converts reserved words like select, from, and count to uppercase (SELECT, FROM, COUNT) while keeping table aliases and column names untouched.
Unchecking Uppercase keywords normalizes reserved words to lowercase if your team style guide prefers lowercase SQL. Changing any option updates Formatted output immediately without re-uploading or reloading the page.
How does a SQL formatter compare to a linter when parsing casts and strings?
Unlike a database linter that validates schema tables or flags slow joins, a formatter focuses purely on layout and lexical safety. Naive find-and-replace formatters corrupt SQL by uppercasing words inside quotes or breaking table.column references at reserved keywords, whereas token-aware lexing classifies every string, comment, operator, and identifier first.
Preserving :: casts, table.column names, and BETWEEN clauses
When you format a PostgreSQL query, lexical rules in the PostgreSQL SQL Lexical Structure Documentation distinguish keywords from single-quoted string constants, double-quoted identifiers, and :: cast operators. The tokenizer keeps '2024-01-01', "select", and payload::jsonb intact with zero extra spaces around dots or double colons.
Inside WHERE and HAVING clauses, AND and OR start new indented lines unless they appear inside a function call or a BETWEEN x AND y range expression. If you are preparing database schema migrations across branches, compare two formatted SQL migration scripts side by side to spot every altered column or index.
Handling multiple semicolon-separated statements and comments
You can paste a full migration script containing multiple queries terminated by ;. The formatter separates each statement with 1 blank line, resets indentation depth at every semicolon, and keeps -- single-line comments and /* ... */ block comments in place.
Client-side privacy and Web Worker speed for large .sql scripts
Database queries often contain internal table schemas, customer emails in WHERE filters, or proprietary reporting logic that should never leave your workstation. Running 100% of tokenization and formatting locally in JavaScript keeps sensitive SQL completely private on your device.
Keeping schema names and production filters off remote servers
Unlike hosted SQL beautifiers that POST your query to a backend API, this tool processes every character inside your browser tab. You can disconnect from the network once the page loads and continue formatting .sql files with zero external requests.
When you need to inspect JSON columns extracted from PostgreSQL jsonb queries, validate and prettify exported JSON payloads locally in the same privacy-first workflow.
Non-blocking worker formatting for multi-statement files
Large migration dumps and generated ORM scripts are routed to a background thread built on the MDN Web Workers API Reference. Offloading tokenization keeps typing and dropdown controls responsive whether you paste a 20 KB query or a 1 MB .sql migration file.
When should you format SQL vs minify it to one line?
Use Format mode during code reviews, query optimization, and documentation so every join, filter, and subquery is clear. Switch to One line mode when pasting queries into environment variables, JSON configs, shell commands, or single-line log filters where newlines and comments cause issues.
Both modes handle standard DDL and DML statements aligned with ISO/IEC 9075 SQL standards and the MySQL 8.4 SQL Statement Syntax Reference. Running 100% locally in a background Web Worker ensures even 50 KB migration files format cleanly without stalling your browser. Compare both modes and option behaviors in the table below.
| Mode or option | Indent & casing | Comments (--, /* */) |
Line breaks | Best use case |
|---|---|---|---|---|
| Format (2 spaces) | 2-space indent, UPPER keywords | Preserved | One clause per line | Pull requests, docs, IDE editing |
| Format (4 spaces) | 4-space indent, UPPER keywords | Preserved | One clause per line | Python/SQL style guides, wide screens |
| Format (Tabs) | Tab indent, lower/UPPER | Preserved | One clause per line | Tab-indented repositories |
| One line | Single space, original case | Stripped completely | Removed (1 line) | Shell args, logs, compact configs |
Tip: Before embedding a query inside a YAML deployment manifest or config file, switch to One line to strip comments and newlines, or convert structured config payloads with JSON to YAML.