# SQL Formatter & Minifier

> Format SQL for PostgreSQL, MySQL, MariaDB, SQLite, SQL Server, BigQuery and Snowflake, or minify it to one line. Comments, strings and placeholders stay.

- Page: https://notadevblog.com/en/tools/developer/sql-formatter/
- German version: https://notadevblog.com/de/tools/developer/sql-formatter.md
- Category: Developer

## At a glance

- **Processing:** Locally in your browser, also offline once the page has been opened. Input never leaves your device.
- **Dialects:** Standard SQL, PostgreSQL, MySQL, MariaDB, SQLite, SQL Server, BigQuery, Snowflake
- **Kept as written:** Comments, strings, dollar quoting, placeholders (?, $1, :name, @name) and MySQL DELIMITER blocks

## For agents

WebMCP: the page registers these functions via document.modelContext in browsers that support it.
ES module: https://notadevblog.com/core/sql-formatter.js
Every function returns { "ok": true, ... } or { "ok": false, "error": { "code", "message" } }.

### sql_format

Pretty-prints SQL with one clause per line and indented column lists, or minifies it to a single line. Pick the dialect so its syntax is understood: sql (standard), postgresql, mysql, mariadb, sqlite, tsql (SQL Server), bigquery, snowflake. Comments are kept when formatting and dropped when minifying (optimizer hints /*! ... */ and /*+ ... */ stay). Strings, quoted identifiers and PostgreSQL dollar quoting ($$...$$, $tag$...$tag$) are never changed. Placeholders stay as written: ? (sql, mysql, mariadb, snowflake), $1 (sql, postgresql), :name (sql, postgresql, mysql, mariadb, snowflake), @name (sql, tsql, bigquery). MySQL/MariaDB DELIMITER commands are understood: statements under a custom delimiter are formatted one by one and the DELIMITER lines are kept. keywordCase changes only keywords (default preserve); indent is spaces per level (default 2). The SQL is not executed and not checked against a schema; a syntax the formatter cannot read returns parse_error with line, column and the unexpected token (empty for end of input). Input limit 2097152 bytes (2 MB).

Parameters:
- sql (string, required): The SQL text, one or more statements.
- dialect (string: sql | postgresql | mysql | mariadb | sqlite | tsql | bigquery | snowflake, default "sql")
- keywordCase (string: preserve | upper | lower, default "preserve")
- indent (integer, default 2, 1..8)
- mode (string: format | minify, default "format")

Example input: `{"sql":"select id, name from users where status = 'active' and created_at > ? order by name","dialect":"postgresql","keywordCase":"upper"}`

Deep link (options in the query, user data after #): https://notadevblog.com/en/tools/developer/sql-formatter/?dialect=postgresql&keywordCase=upper#sql=select+id%2C+name+from+users+where+status+%3D+%27active%27+and+created_at+%3E+%3F+order+by+name

## How to use

1. **Paste your SQL:** Paste one or more statements, up to 2 MB. Choose the dialect your database speaks.
2. **Choose the style:** Pick upper, lower or unchanged keywords and the indent width, or switch to minify for a single line.
3. **Copy the result:** The result updates as you type. If the formatter cannot read something, it shows the line and column.

## About this tool

Formatted SQL is easier to review: one clause per line, column lists indented, keywords in one case. The layout comes from the open-source library sql-formatter.

Large files are formatted in a background thread, so the page stays responsive.

## Frequently asked questions

### Does the formatter check my SQL?

Only the syntax it needs to lay the code out. It does not run the query and does not know your tables, so a wrong column name is not reported.

### Which dialect should I pick?

The one of your database. It decides which quotes, comments and placeholders are understood, for example backticks in MySQL, [brackets] in SQL Server or $1 and $$ strings in PostgreSQL. Standard SQL works for simple queries.

### What happens to DELIMITER in MySQL scripts?

The DELIMITER lines are kept. Each statement under a custom delimiter, such as a stored procedure ending in //, is formatted on its own and keeps its delimiter.

### What does minify remove?

Comments and extra whitespace. Optimizer hints in /*! ... */ and /*+ ... */ stay, and nothing inside strings or quoted names changes.
