SQL Formatter
Pretty-print SQL queries with keyword case and indentation. Supports Postgres, MySQL, SQLite, T-SQL, BigQuery, and more.
0 characters
0 characters
About SQL Formatter
The SQL formatter parses and re-emits SQL statements with consistent indentation, keyword case, and clause alignment. It uses the sql-formatter library, which understands a dozen SQL dialects and most common syntax extensions (CTEs, window functions, JSON operators, MERGE statements).
When to use it
- Reading a long query copied out of an application log
- Cleaning up SQL embedded in source code for a review
- Reformatting a stored procedure or migration before committing
- Standardizing keyword case across a project (UPPER vs lower)
- Making complex joins and subqueries easier to follow
How it works
The query is tokenized into keywords, identifiers, literals, and operators by sql-formatter's parser. The formatter re-prints the query with each major clause (SELECT, FROM, WHERE, GROUP BY) on its own line, sub-clauses indented, and keywords in uppercase by default.
Examples
Inline → indented with uppercase keywords
select id,name,email from users where active=true and created_at>'2024-01-01' order by name limit 10;
SELECT id, name, email FROM users WHERE active = true AND created_at > '2024-01-01' ORDER BY name LIMIT 10;
Frequently asked questions
- Which SQL dialect is used?
- The default is standard SQL. The formatter recognizes dialect-specific syntax from Postgres, MySQL, SQLite, MariaDB, MS SQL Server (T-SQL), BigQuery, Snowflake, Redshift, and SparkSQL. For dialect-specific tweaks, integrate sql-formatter directly into your toolchain.
- Does it execute the query?
- No. The formatter only restyles the SQL — it never connects to a database, never executes anything, and never sees your data.
- Is keyword case configurable?
- The output uses uppercase keywords (SELECT, FROM, WHERE). To match a project that uses lowercase keywords, post-process with the lowercase tool, or integrate sql-formatter with custom options.
- What about comments?
- Single-line (--) and block (/* ... */) SQL comments are preserved through formatting.
- Is my SQL uploaded anywhere?
- No. Formatting runs in your browser via the sql-formatter library.