SQL Formatter

Beautify SQL per dialect, including MySQL and PostgreSQL

Runs in your browserUtility01Formatters & Validators

What is SQL Formatter?

A SQL formatter rewrites single-line or inconsistently indented statements into readable SQL with proper line breaks and alignment, and it understands the keyword differences between MySQL, PostgreSQL, SQL Server, SQLite, BigQuery, and other dialects. Everything runs inside the browser, so your SQL is never uploaded.

How to use SQL Formatter

  1. 1Paste your SQL — a single statement or several separated by semicolons.
  2. 2Choose the target dialect; dialects differ in how they handle quoting, functions, and reserved words.
  3. 3Pick a keyword case style (upper, lower, or preserve) and an indentation width.
  4. 4Copy the formatted output, or keep adjusting the options until it matches your team conventions.

How do I do this in code?

Use the tool above for one-off work; for anything you repeat, move it into a script or your project.

import { format } from 'sql-formatter';

const pretty = format(sql, {
  language: 'postgresql',
  keywordCase: 'upper',
  tabWidth: 2,
});

Common errors and how to fix them

SymptomCauseFix
Dialect-specific syntax is broken apart in the formatted outputThe selected dialect does not match the SQL you pasted — parsing a PostgreSQL :: cast as MySQL, for instance.Switch the dialect to the database the statement actually targets.
SQL containing template variables fails to formatThe {{ }} or :param placeholders from an ORM template are not valid SQL tokens.Substitute literal values for the placeholders before formatting, or leave that fragment as-is and skip it.

Frequently asked questions

Does this SQL formatter run my query?+

No. The tool only rearranges the statement at the lexical and syntactic level; it never connects to a database and never inspects data. Pasting a production statement with real table names is safe because the text never leaves your browser.

Which SQL dialects are supported?+

MySQL, MariaDB, PostgreSQL, SQL Server (T-SQL), SQLite, BigQuery, Snowflake, and Spark SQL, among others. The dialect drives reserved-word detection and quoting rules, so choosing the right one gives you more accurate line breaks.

Why does the same query come out differently for different people on my team?+

Because three settings differ: indentation width, keyword case, and dialect. Agree on one combination, write it into your style guide, or better still run the same formatter in CI so everyone gets identical output.

Related tools

All tools