# SQL Formatter > A free SQL formatter that runs in the browser: paste a query or open a .sql file and it is formatted as you type, with a free check for common mistakes. https://sql-formatter.skillsafe.ai/ ## What it does (free, no sign-in, nothing uploaded) - Formats one query or a whole script with the open-source sql-formatter library, for standard SQL, PostgreSQL, MySQL, MariaDB, SQL Server, Oracle, SQLite, BigQuery, Snowflake, Redshift, Spark/Databricks, DuckDB, Trino/Presto, Db2 and Hive. The dialect is detected from the SQL (backticks, square brackets, :: casts, QUALIFY, NVL and so on) or chosen by hand. - Options: keyword case, indent (2 or 4 spaces or a tab), function and data type case, standard or tabular layout, AND/OR at the start or end of a line, line width, blank lines between statements, dense operators, semicolon on its own line. Names, strings and numbers are never changed. - Free check with line numbers: = NULL comparisons, UPDATE or DELETE without WHERE, JOIN without ON, LEFT JOIN undone by a WHERE filter, NOT IN over a subquery, comma joins, SELECT *, functions wrapped around filtered columns, IN over a subquery, one-letter aliases, GROUP BY / ORDER BY by position, LIKE starting with %, UNION instead of UNION ALL, subqueries nested three deep, subqueries in the SELECT list, HAVING without an aggregate. - Exports: copy, copy as one line (line comments become block comments), copy as a Markdown sql block, download .sql. - Parse errors name the line and column and say what to do next. ## Optional AI step (signed-in, metered) "Rewrite with AI" returns the SQL rewritten to the best practices of the write-query skill in the same dialect (fixes where SQL can fix them, CTEs instead of nested subqueries, explicit joins, NOT EXISTS, range filters on bare columns, meaningful aliases), applying an optional request, with a list of changes, the checks it kept on purpose, and whether the results change. The page formats the rewrite, re-runs the check on it, and flags any table or column not in the visitor's SQL, any claimed fix the check still finds, and any new problem. It never writes a WHERE the visitor did not give. - API: https://sql-formatter.skillsafe.ai/api.html - Input fields: `task` ("rewrite"), `sql` (the formatted SQL, whole statements, at most 12,000 characters), `dialect` (a formatter id such as postgresql, mysql, transactsql, snowflake), `request` (optional, up to 300 characters), `facts` (JSON text: the check's findings `{id, kind, line, key}`, tables, CTE names, statement count), `clipped_note`. - Output: one ```json object: `task`, `sql`, `same_results`, `result_change`, `changes` (`{kind, check, what}`), `kept` (`{check, reason}`), `notes`. ## Source Adapted from the agent skill @anthropics/write-query by Anthropic (https://github.com/anthropics/knowledge-work-plugins, Apache-2.0): https://skillsafe.ai/skill/@anthropics/write-query Formatting: sql-formatter 15.6.5 (https://github.com/sql-formatter-org/sql-formatter, MIT).