[ advertisement ]

SQL Formatter

Turn one-line queries into readable SQL with aligned clauses, consistent keywords and configurable indentation for your database dialect.

SQL

Formatted

SELECT
    u.id,
    u.name,
    count(o.id) AS total
FROM
    users u
    LEFT JOIN orders o ON o.user_id = u.id
WHERE
    u.created_at >= '2026-01-01'
    AND u.active = TRUE
GROUP BY
    u.id,
    u.name
HAVING
    count(o.id) > 5
ORDER BY
    total DESC
LIMIT
    10;

Use via API

Formats a SQL query.

POSThttps://enhanced.dev.br/api/v1/sql/format
JSON body parameters
Body (JSON)TypeDescription
sql *stringQuery to format.
language"postgresql" | "mysql" | "sqlite"Dialect. Default: "postgresql".
keywordCase"upper" | "lower" | "preserve"Default: "upper".
tabWidth2 | 4Default: 2.

Request example

curl -X POST "https://enhanced.dev.br/api/v1/sql/format" \
    -H "Content-Type: application/json" \
    -d '{"sql":"select id, name from users where active = true order by name","language":"postgresql","keywordCase":"upper","tabWidth":4}'

Response

{
  "ok": true,
  "data": {
    "language": "postgresql",
    "output": "SELECT\n    id,\n    name\nFROM\n    users\nWHERE\n    active = TRUE\nORDER BY\n    name"
  },
  "meta": {
    "version": "v1"
  }
}
  • Errors return { ok: false, error: { code, message } } with an HTTP 4xx/5xx status.
  • Free, no API key required. Limited to 120 requests per minute per IP.
  • CORS enabled: call it straight from the browser on any domain.
[ advertisement ]

How to use

  1. Paste the query into the SQL panel.
  2. Choose the dialect: PostgreSQL, MySQL or SQLite.
  3. Set the keyword case and indentation.
  4. Copy the formatted query.

Use cases

  • Reading queries generated by ORMs and captured in logs.
  • Standardizing SQL in code reviews and migrations.
  • Documenting queries in wikis and tickets.

Technical concepts

Why the dialect matters

Each database has its own syntax: PostgreSQL uses :: for casts and $1 for parameters, MySQL uses backticks for identifiers and SQLite accepts flexible types. Picking the right dialect keeps the formatter from misreading these tokens.

Style conventions

Uppercase keywords and each main clause (SELECT, FROM, WHERE, GROUP BY, ORDER BY) on its own line are the most widespread conventions, making queries easier to read and diffs smaller in version control.

Frequently asked questions

Does formatting change the query result?

No. Only whitespace, line breaks and keyword case change; identifiers and literals are preserved.

Why do I get a parse error?

The formatter did not recognize a token in the chosen dialect, such as syntax specific to another database. Try another dialect or check parentheses and quotes.

Related tools