What this SQL formatter does
This tool does two jobs. First, it formats SQL: one clause per line, consistent indentation, upper- or lower-case keywords and readable JOIN and CASE blocks, using the battle-tested sql-formatter engine with dialect-aware parsing. Second, it performs basic dialect conversion between MySQL, PostgreSQL, SQLite and SQL Server, handling the differences that bite most often when moving a query or a schema between databases. Everything runs locally, so production queries containing real table names never leave your browser.
How to use it
- Paste SQL into the input.
- Choose the source dialect and, if you want to convert, a target dialect. Leave the target as "keep" to only format.
- Pick keyword case and indentation width.
- Review the notes panel: anything the converter could not translate safely is listed there.
- Copy the result.
Practical examples
- Messy dump from an ORM: paste a single-line
SELECTwith nested joins and format it so you can see whichONclause belongs to which table. - Moving a schema to Postgres: convert MySQL
CREATE TABLEwith`id` INT AUTO_INCREMENTinto PostgreSQL"id" SERIAL(orGENERATED BY DEFAULT AS IDENTITY). - Porting a report query: rewrite
LIMIT 20 OFFSET 40for SQL Server asOFFSET 40 ROWS FETCH NEXT 20 ROWS ONLY, and swapIFNULLforCOALESCE. - Code review: format both the old and new query with the same settings before diffing them, so whitespace noise disappears.
What the converter handles
- Identifier quoting:
`name`(MySQL) ↔"name"(PostgreSQL/SQLite) ↔[name](SQL Server). - Row limits:
LIMIT n OFFSET m↔TOP n↔OFFSET m ROWS FETCH NEXT n ROWS ONLY. - Auto-increment:
AUTO_INCREMENT↔SERIAL/GENERATED ... AS IDENTITY↔AUTOINCREMENT↔IDENTITY(1,1). - Common types:
DATETIME/TIMESTAMP,TINYINT(1)/BOOLEAN/BIT,NVARCHAR,TEXT,BLOB/BYTEA/VARBINARY(MAX). - Functions:
NOW()/GETDATE()/CURRENT_TIMESTAMP,IFNULL/ISNULL/COALESCE,RAND()/RANDOM(),CONCAT↔||. - String literals and comments are protected, so a keyword inside
'quotes'is never rewritten.
Tips and limitations
- Dialect conversion is pattern-based, not a full compiler. Stored procedures, triggers, vendor-specific JSON operators,
MERGE,ON DUPLICATE KEYvsON CONFLICTand collation details need a manual review. - Treat the output as a strong first draft and run it against the target database before shipping.
- Prefer formatting before converting: a readable query is easier to spot when a rewrite was incomplete.
- Keep the source dialect correct. Feeding Postgres SQL marked as MySQL can produce wrong quoting.