TotalApp Docs

SQL Formatter

Paste raw SQL and get it back clean, indented, and syntax-highlighted.

Overview

The SQL Formatter takes any SQL statement — no matter how minified, inconsistently cased, or awkwardly spaced — and reformats it with consistent indentation, aligned clauses, and your preferred keyword casing. The formatted result updates in real time in the right panel as you type or paste SQL into the left panel.

No Execution, No Network

The formatter only reformats your SQL text. It does not execute the query, connect to a database, or send data anywhere. All processing happens in the browser.

Real-Time Formatting

The formatted output panel refreshes as you type. No need to click a Format button — changes appear instantly.

Keyword Casing

Choose UPPERCASE, lowercase, or Title Case for SQL keywords. The casing setting applies globally across the entire query.

Configurable Indent

Set indentation to 2 spaces, 4 spaces, or a hard tab. The indent applies to nested clauses, subqueries, and CTE blocks.

Comment Preservation

Inline (-- comment) and block (/* comment */) comments are preserved exactly as written and positioned above the nearest clause.

Supported Dialects

The formatter handles standard ANSI SQL and dialect-specific extensions for all major databases. Dialect-specific syntax is formatted around its surrounding clauses and preserved exactly.

DialectSupported Extensions
PostgreSQLON CONFLICT DO UPDATE, RETURNING, JSONB operators, WITH RECURSIVE CTEs, window functions
MySQL / MariaDBLIMIT x OFFSET y, ON DUPLICATE KEY UPDATE, backtick identifiers, STRAIGHT_JOIN
SQLitePRAGMA statements, WITHOUT ROWID, UPSERT syntax
SQL Server (T-SQL)TOP N, WITH (NOLOCK), OUTPUT clause, square-bracket identifiers, GO batches
ANSI SQLAll standard DML and DDL: SELECT, INSERT, UPDATE, DELETE, CREATE/ALTER/DROP TABLE, CTEs, subqueries, joins

Dialect Auto-Detection

The formatter attempts to detect the dialect automatically from keywords in your SQL (e.g. TOP implies T-SQL, RETURNING implies PostgreSQL). You can override detection with the Dialect selector in the toolbar if needed.

Formatting Options

All options are available in the toolbar above the input panel and take effect immediately.

OptionValuesDefaultEffect
Indent Size2 spaces · 4 spaces · Tab2 spacesControls indentation of nested clauses and subqueries
Keyword CaseUPPER · lower · TitleUPPERApplies uniform casing to all SQL reserved words
Comma PositionEnd of line · Start of lineEnd of linePlaces commas at the end or beginning of each list item in SELECT and INSERT
Newline Before KeywordsOn · OffOnPlaces major clause keywords (WHERE, AND, JOIN, ORDER BY) on their own line
Compact ModeOn · OffOffReduces blank lines between clauses for a denser output

Keyboard Shortcuts

ShortcutAction
Ctrl+Shift+F / Cmd+Shift+FForce re-format the current input (useful after changing options)
Ctrl+A / Cmd+ASelect all text in the active panel
Ctrl+C / Cmd+CCopy selected text in the active panel
Ctrl+Shift+C / Cmd+Shift+CCopy entire formatted output to clipboard (from anywhere)
Ctrl+DeleteClear the input panel

Copy & Export

Formatted SQL can be copied or exported from the right panel toolbar.

  • Copy — Copies the entire formatted output to the clipboard. The button turns green briefly to confirm the copy succeeded.
  • Download .sql — Downloads the formatted SQL as a .sql file. The filename is formatted-query.sql by default; rename the file after downloading.
  • Share Link — Generates a shareable URL that encodes the current input SQL in the URL fragment. The recipient opens the link and sees the same SQL pre-loaded in the input panel.

Format Before Code Review

Run your SQL through the formatter before including it in a pull request or documentation. Consistent indentation and casing makes SQL reviews significantly faster and catches misplaced clauses that are invisible in minified code.

AI Assistant

Open the built-in AI Assistant from the tab on the right edge of the screen to get help with your SQL. The assistant sees the selected dialect, the current SQL text, and the linter's findings, so you can ask things like:

  • "Explain the top linter issue and how to fix it"
  • "How can I optimize this query for better performance?"
  • "Walk me through what this SQL does step by step"
  • "What would change if I ran this on MySQL instead of PostgreSQL?"

The assistant does not execute the query or see a real query plan — it reasons over the SQL text and the static linter findings shown on screen.

FAQ

The formatter produced an error for my SQL — what should I do?
The formatter highlights the position of syntax it could not parse with a red underline in the input panel. Check for unclosed parentheses, mismatched quotes, or dialect-specific syntax that may need the correct Dialect selected in the toolbar. If the SQL is valid but still fails, try switching the Dialect setting manually.
Are stored procedures and PL/pgSQL blocks supported?
Basic CREATE PROCEDURE and CREATE FUNCTION wrappers are formatted correctly. The body of procedural language blocks (PL/pgSQL $$...$$, T-SQL BEGIN...END) is preserved as-is and not reformatted, since procedural code has its own conventions that differ from SQL.
Does formatting change the meaning of my SQL?
No. The formatter only adds and removes whitespace and changes keyword casing. It never reorders clauses, adds or removes parentheses, or modifies string literals. The logical result of the query is identical before and after formatting.
Is there a size limit for SQL input?
The formatter handles queries up to approximately 1 MB of text without performance issues. Very large SQL files (e.g. full database dumps with thousands of INSERT statements) should be split into sections and formatted individually for best performance.