Skip to SQL formatter
Edwin Lab

SQL Formatter

Format PostgreSQL or MySQL query text with clear indentation and keyword case. Your query stays in this browser.

Up to 5 MiB UTF-8. Format with the button or Ctrl/⌘ + Enter. A formatter does not validate your database schema.

Select and copy manually if clipboard access is unavailable.

Ready. Choose the SQL dialect and enter a query.

Format SQL in three steps

  1. Choose PostgreSQL or MySQL to match the query syntax.
  2. Set indentation and how recognized keywords appear.
  3. Format, review, then copy or download the result.

Formatting reorganizes whitespace and recognized keywords; it does not convert a query between dialects. The formatter may reject syntax it does not support. Your input stays available for editing if formatting fails.

Before and after

This example is available above as PostgreSQL:

Before:
select id,name from users where active=true;

After (2 spaces, uppercase keywords):
SELECT
  id,
  name
FROM
  users
WHERE
  active = TRUE;

The exact result follows the bundled formatter version and selected options.

What the options change

Dialect controls how the library recognizes PostgreSQL or MySQL tokens. Use the query's existing dialect; this setting does not rewrite dialect-specific constructs. Indentation chooses 2 spaces, 4 spaces, or tabs. Keyword case affects only keywords recognized by the formatter. Preserve leaves their input case; quoted identifiers and string literals remain as written.

Frequently asked questions

Are quoted strings preserved?

Yes. String contents, quoted identifiers, placeholders, comments, and PostgreSQL dollar-quoted bodies are kept by the formatter when supported by the selected dialect.

What is the difference between PostgreSQL and MySQL here?

The selected dialect changes token recognition and formatting rules. The query is not converted, executed, or checked against a database.

Why might some syntax not be supported?

The pinned SQL formatter covers a defined set of dialect tokens. Unsupported syntax can produce a formatting error. A successful format does not prove that a database accepts the query.

Technical details and related tools

This page uses local sql-formatter 15.6.10 and processes queries in a temporary browser worker. It does not run SQL, inspect schemas, validate query safety, or promise execution compatibility. Validate structured output with JSONLint, convert tabular data with the JSON to CSV converter, or browse Developer Tools.