# SQL formatter

> Format SQL for PostgreSQL, MySQL, BigQuery, Snowflake, and other dialects.

Free SQL formatter. Pick a dialect, choose upper, lower, or preserved keywords, and indent with 2 or 4 spaces. Formatting runs in the browser.

- Page: https://benchline.fabwaseem.com/t/sql-formatter
- Runs: in the browser. Input stays on the device.
- Price: free, no account
- Input: SQL text, a dialect, keyword case, and an indent of 2 or 4 spaces.
- Output: Formatted SQL.
- Keywords: sql formatter, format sql, postgresql formatter
- Updated: 2026-10-18
- Built by: Waseem Anjum (https://fabwaseem.com)

## How to use it

1. **Paste a query.** Drop a SELECT, an INSERT, or a longer script into the editor.
2. **Pick a dialect.** Keyword rules differ. PostgreSQL and BigQuery are both in the list.
3. **Copy the formatted SQL.** Choose keyword case and indent, then copy or download the result.

## Use it from an AI agent

MCP tool name: `format_sql`
MCP endpoint: https://benchline.fabwaseem.com/mcp (Streamable HTTP, no key)
HTTP: POST https://benchline.fabwaseem.com/api/v1/tools/sql-formatter with the input as the JSON body
This call does not fetch anything. It runs on the arguments you send.

Format SQL for PostgreSQL, MySQL, BigQuery, Snowflake, and other dialects. Choose keyword case and an indent of 2 or 4 spaces.

### Input schema

```json
{
  "type": "object",
  "properties": {
    "sql": {
      "type": "string",
      "description": "SQL to format."
    },
    "dialect": {
      "default": "postgresql",
      "type": "string",
      "enum": [
        "postgresql",
        "mysql",
        "mariadb",
        "sqlite",
        "transactsql",
        "bigquery",
        "snowflake",
        "redshift",
        "spark",
        "hive",
        "plsql",
        "trino",
        "sql"
      ]
    },
    "keywordCase": {
      "default": "upper",
      "type": "string",
      "enum": [
        "upper",
        "lower",
        "preserve"
      ]
    },
    "indent": {
      "default": 2,
      "anyOf": [
        {
          "type": "number",
          "const": 2
        },
        {
          "type": "number",
          "const": 4
        }
      ]
    }
  },
  "required": [
    "sql",
    "dialect",
    "keywordCase",
    "indent"
  ],
  "additionalProperties": false
}
```

### Example tools/call

```json
{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "tools/call",
  "params": {
    "name": "format_sql",
    "arguments": {
      "sql": "example",
      "dialect": "postgresql",
      "keywordCase": "upper",
      "indent": 2
    }
  }
}
```

Setup for Claude, Cursor, and VS Code: https://benchline.fabwaseem.com/mcp/guide

## Questions

### Does this run the query?

No. It only changes whitespace and keyword case. It does not connect to a database.

### Which dialects are included?

PostgreSQL, MySQL, MariaDB, SQLite, T-SQL, BigQuery, Snowflake, Redshift, Spark, Hive, PL/SQL, Trino, and a standard SQL dialect.

### Will it fix a syntax error?

It formats the text it can read. A broken query may still format, or it may report that it could not be formatted. It does not rewrite the logic.

## Related tools

- [JSON formatter](https://benchline.fabwaseem.com/t/json-formatter): Pretty-print, minify, and validate JSON, with the exact line and column when it fails.
- [Regex tester](https://benchline.fabwaseem.com/t/regex-tester): Test a JavaScript pattern, read the groups, and preview a replacement.
- [JSON YAML converter](https://benchline.fabwaseem.com/t/json-yaml-convert): Convert JSON, YAML, TOML, and XML in the browser, and keep the line number when a document fails.
- [CSV JSON converter](https://benchline.fabwaseem.com/t/csv-json-convert): Convert CSV to JSON and JSON back to CSV, with a delimiter and a header row you choose.
