Xerobit

SQL Formatter

Format SQL queries with dialect-aware rules. Handles PostgreSQL, MySQL, SQLite, MSSQL (T-SQL), Oracle PL/SQL, DB2, BigQuery, Snowflake, Redshift, Spark SQL, and standard SQL. Keyword casing control.

Dialect matters

SQL is a standard and also 30 dialects. Each vendor extended it: PostgreSQL added ::type casts, MySQL added backticks, BigQuery added EXCEPT(...), Snowflake added LATERAL FLATTEN. A dialect-unaware formatter mangles these or treats them as syntax errors.

Pick the dialect matching your target database. The formatter preserves dialect-specific syntax instead of flagging it.

Keyword case conventions

  • UPPER (default): SELECT, FROM, WHERE. Oldest convention, most common in documentation and DBA tooling.
  • lower: select, from, where. Modern convention in many application codebases (SQLAlchemy, Prisma docs).
  • preserve: leave as-is. Use when a style guide forbids auto-rewriting.

What the formatter will and won't do

Does:

  • Insert newlines at clause boundaries (SELECT, FROM, WHERE, JOIN, GROUP BY, ORDER BY)
  • Align column lists, indent subqueries
  • Normalize whitespace, strip trailing whitespace
  • Preserve comments (both -- and /* */)
  • Respect dialect-specific syntax

Does not:

  • Execute the query
  • Validate referenced tables/columns exist
  • Optimize or rewrite the query
  • Send your SQL anywhere: it runs entirely in your browser

FAQ

Can I paste a stored procedure?

Yes, especially in T-SQL or PL/SQL modes. Complex control flow, variable declarations, and cursor loops format correctly.

Will it break on dialect mismatches?

Usually not, it will still format but may leave dialect-specific tokens un-indented. Match the dialect for best results.

Is my SQL uploaded anywhere?

No. The sql-formatter library runs in your browser.

Pillar