Skip to main content
The SQL formatter helps you format and beautify SQL queries with support for multiple database dialects. It provides both formatting and minification options with customizable settings.

Features

Multi-dialect support

Format SQL for different database systems:
  • PostgreSQL - Full PostgreSQL syntax support
  • MySQL - MySQL-specific formatting
  • MariaDB - MariaDB syntax support
  • PL/SQL - Oracle PL/SQL formatting
The formatter uses the sql-formatter library and dynamically loads it to optimize bundle size.

Format SQL

Beautify SQL with proper indentation and structure:
  • Configurable indentation (2 or 4 spaces)
  • Keyword case formatting (UPPERCASE or lowercase)
  • Line breaks between queries
  • Standard indentation style
  • Readable output

Minify SQL

Compress SQL to a single line:
  • Remove unnecessary whitespace
  • Reduce query size
  • Optimize for transmission
  • Useful for embedding in code

Configuration options

SQL dialect

Choose the database dialect for optimal formatting:
  • PostgreSQL (default)
  • MySQL
  • MariaDB
  • PL/SQL (Oracle)

Tab width

Set indentation width:
  • 2 spaces (default)
  • 4 spaces

Keyword case

Format SQL keywords:
  • UPPERCASE (default) - SELECT, FROM, WHERE
  • lowercase - select, from, where
Most SQL style guides recommend UPPERCASE keywords for better readability.

Use cases

Query development

Format messy queries during development:
SELECT id, name, email FROM users WHERE status = 'active' AND created_at > '2024-01-01' ORDER BY name ASC LIMIT 10;
Formats to:
SELECT
  id,
  name,
  email
FROM
  users
WHERE
  status = 'active'
  AND created_at > '2024-01-01'
ORDER BY
  name ASC
LIMIT
  10;

Code review

Format SQL before committing to version control for consistency.

Query optimization

Beautify complex queries to identify optimization opportunities:
SELECT
  u.id,
  u.name,
  COUNT(o.id) AS order_count
FROM
  users u
  LEFT JOIN orders o ON u.id = o.user_id
WHERE
  u.status = 'active'
GROUP BY
  u.id,
  u.name
HAVING
  COUNT(o.id) > 5
ORDER BY
  order_count DESC;

Documentation

Format SQL examples in documentation for better readability.

Examples

The formatter includes built-in examples:

Simple SELECT query

SELECT id, name, email FROM users WHERE status = 'active' AND created_at > '2024-01-01' ORDER BY name ASC LIMIT 10;

JOIN with aggregation

SELECT u.id, u.name, COUNT(o.id) as order_count FROM users u LEFT JOIN orders o ON u.id = o.user_id WHERE u.status = 'active' GROUP BY u.id, u.name HAVING COUNT(o.id) > 5 ORDER BY order_count DESC;

Multi-row INSERT

INSERT INTO products (name, price, category_id, created_at) VALUES ('Laptop', 999.99, 1, NOW()), ('Mouse', 29.99, 2, NOW()), ('Keyboard', 79.99, 2, NOW());

UPDATE with conditions

UPDATE orders SET status = 'shipped', shipped_at = NOW() WHERE status = 'processing' AND created_at < DATE_SUB(NOW(), INTERVAL 1 DAY);

CTE with window function

WITH monthly_sales AS (SELECT DATE_TRUNC('month', order_date) as month, SUM(total) as revenue FROM orders GROUP BY 1) SELECT month, revenue, LAG(revenue) OVER (ORDER BY month) as prev_month FROM monthly_sales;
Click “Examples” to load these queries and see how they format in different dialects.

Output feedback

The formatter provides visual confirmation:
  • Formatted badge - Green checkmark when formatting succeeds
  • Minified badge - Indicates compressed output
  • Dialect badge - Shows which SQL dialect was used
  • Error alerts - Displays formatting errors if any

Copy functionality

Copy formatted SQL to clipboard:
  • Click the copy button on the output section
  • Formatted SQL is copied with proper indentation
  • Use in your code editor or database tool

Keyboard shortcuts

  • Cmd/Ctrl + Enter - Format SQL
  • Cmd/Ctrl + K - Clear all inputs
  • Cmd/Ctrl + C - Copy formatted output

Tips

Format SQL before saving to version control to maintain consistent code style across your team.
Use minify when embedding SQL in configuration files or environment variables to reduce size.
Switch dialects to see how different databases format the same query - useful for migrations.

Performance

The formatter uses dynamic imports:
  • The sql-formatter library loads on first use
  • Reduces initial page load time
  • Shows loading spinner during formatting
  • Optimized for large queries

Build docs developers (and LLMs) love