Skip to content
Expensico

SQL Formatter

Beautify SQL queries for PostgreSQL, MySQL, SQL Server, SQLite, BigQuery and more, with keyword case and indentation options.

Runs in your browser. Everything you enter stays on your device. Nothing is sent to a server.

How to use the SQL Formatter

  1. Paste a query or open a .sql file.
  2. Choose your database dialect, keyword case and indentation.
  3. Copy or download the formatted SQL.

Why format SQL?

Queries copied from ORMs, logs and monitoring tools arrive on one line. Consistent formatting — one clause per line, indented joins and conditions, uppercase keywords — makes them far easier to review, debug and diff.

Dialect matters

Each database has its own syntax: PostgreSQL's :: casts and $1 parameters, MySQL's backtick identifiers, T-SQL's square brackets, BigQuery's backtick table paths. Choosing the right dialect lets the formatter recognise them instead of breaking them apart.

Supported dialects and options

Choose from Standard SQL, PostgreSQL, MySQL, MariaDB, SQLite, SQL Server (T-SQL), Oracle PL/SQL, BigQuery, Snowflake, Redshift, Spark SQL and DB2. Keywords can be UPPERCASE, lowercase or left as written (Preserve), and indentation can be 2 or 4 spaces. When a file contains several statements separated by semicolons, each is formatted and separated by a blank line.

Team style guides differ mostly on keyword case and indent width, so match whatever your existing migrations or code reviews use — consistency matters more than the choice itself.

What the formatter doesn't do

It changes only whitespace and keyword case. It doesn't validate that tables exist, optimise the query, or run it. Formatting happens in your browser with the open-source sql-formatter library, so queries containing real data stay private.

Example

A one-line query copied from a log:

select o.id, c.name from orders o join customers c on c.id = o.customer_id where c.city in ('Pune','Mumbai') order by o.id;

Formatted for PostgreSQL with uppercase keywords:

SELECT
  o.id,
  c.name
FROM
  orders o
  JOIN customers c ON c.id = o.customer_id
WHERE
  c.city IN ('Pune', 'Mumbai')
ORDER BY
  o.id;

Frequently asked questions

Is my SQL sent anywhere?

No. Formatting runs in your browser, so queries with real customer data or credentials never leave your device.

Which dialect should I choose if I'm not sure?

Pick your database if it's listed. Standard SQL works for simple queries; choose the specific dialect when the query uses vendor syntax such as backticks, square brackets or :: casts.

My query contains template placeholders and fails to format.

Placeholders like {{ variable }} aren't valid SQL. Replace them with a literal or a parameter (?, $1, :name) before formatting.

Does it support stored procedures?

Common procedural blocks for PL/SQL and T-SQL are supported, but very complex procedural code may not format perfectly.