SQL formatter and linter (SQLite / DuckDB)
Pick a .sql file and reformat it: normalise keyword case, put major clauses on their own line, indent by parenthesis depth, collapse stray whitespace, and run structural checks for unbalanced parentheses, unterminated quotes and trailing commas — plus a hex preview of the file. It connects to no database, executes no SQL, and binary database files (.duckdb / Parquet) are rejected explicitly with a byte offset.
Runs in your browserEvery computation happens in your browser — your data never leaves this device.
Pick a .sql text file. It is read locally in your browser and never uploaded; the tool connects to no database.
Pick a file first.
Result
These are the real numbers from this run — copy them straight out.
Pick a file and set the options; the result shows up here.
What this tool does
- Reformat a one-liner SQL snippet someone sent you so it is reviewable and diffable (keyword case, clause breaks, parenthesis indent in one pass)
- Run structural checks before committing: are the parentheses balanced, are strings and block comments closed, is there a stray comma in a list
- Format SQLite / DuckDB flavoured DDL and DML text files (.sql) and download the result as a new .sql
Example
Input
select a, b, from users where id in (1,2,3) and name like '%x%' order by a desc;
Output
SELECT a, b, FROM users WHERE id IN (1,2,3) AND name LIKE '%x%' ORDER BY a DESC; diagnostics: 12 trailing-comma ,
The real result of formatting this file with the defaults (upper-case keywords, 2-space indent); the comma after `b,` is flagged as a trailing comma, hence the diagnostics entry at position 12 (positions are 1-based).
Frequently asked questions
Can it run SQL or query Parquet / CSV / Excel?
No. This is a pure text formatter and structural checker; there is no DuckDB engine on the page (nor a usable DuckDB wasm build in this repository), and to actually run read-only SQLite queries use the sibling sqlite-reader tool. Picking a .duckdb or SQLite binary reports "the file contains NUL bytes" with an offset, and a Parquet file (PAR1 magic) is rejected too instead of being mangled as SQL.
How accurate are the findings?
They come from a tokeniser, not a parser: balanced parentheses, closed quotes and block comments, stray commas, recognisable statement starts. So it will not report semantic problems like a missing function, but it also will not invent errors; for strict validation feed the formatted SQL to a real database with EXPLAIN.
Does the keyword case change strings or data?
No. The tokeniser detects strings, double-quoted identifiers and comments first and only changes words it identified as keywords, so a literal `select` and a column named "Select" stay untouched. The preview also shows the length change (charsBefore → charsAfter).
Which dialects are supported?
The keyword table covers standard SQL plus the clauses and functions common to SQLite and DuckDB, including two-word clauses such as INSERT INTO, CREATE TABLE, PARTITION BY and UNION ALL. Other dialects (T-SQL GO, Oracle PL/SQL blocks) do not fail, they just format and check less accurately. Everything runs locally and nothing is uploaded.
Keywords:SQL formatter