SQL Formatter & Dialect Converter
Format SQL and translate it between MySQL, PostgreSQL and SQLite. Every change is listed, and anything that cannot be translated safely is flagged instead of guessed — all in your browser.
About this tool
SQL looks portable and mostly is — until it is not. The same statement can mean different things in MySQL and PostgreSQL, and the differences are exactly the ones that do not raise an error. PostgreSQL reads "name" as an identifier, MySQL reads it as a string. In MySQL || is logical OR; in PostgreSQL it concatenates. A query moved without fixing those still runs, still returns rows, and returns the wrong ones.
This tool does two things. It reformats SQL so clauses, lists and boolean conditions each get their own line, and it translates between MySQL, PostgreSQL and SQLite. Every rewrite it makes is listed with its before and after text, so you can check the work rather than trust it.
Anything that cannot be translated without guessing is left alone and flagged instead — the :: cast, UPSERT variants, ILIKE, AUTO_INCREMENT, storage engine options. Guessing there would produce SQL that is syntactically valid and semantically different, which is worse than an error. Everything runs in your browser; no query you paste is sent anywhere.
Why LIMIT 50, 25 keeps its comma on one line
A comma only breaks a line when it sits inside a list. SELECT, GROUP BY, ORDER BY, SET and RETURNING are lists; a comma in LIMIT, or inside a function call, separates fixed arguments and is left inline.
The first version of a formatter like this breaks after every top-level comma, and the damage is quiet: a MySQL paging clause becomes three lines and stops reading like a pair of numbers. The offset and the row count belong together, and splitting them hides the fact that they are one clause.
The fix is to know which clause a comma is in before deciding. The formatter tracks the clause it is currently inside, and only the list-shaped ones trigger a break. Inside parentheses nothing breaks at all, since being nested is not the same as being in a top-level list.
OFFSET is deliberately not treated as the start of a clause, for the same reason. It almost always follows LIMIT, and breaking before it would separate the two numbers that are read together. Formatting should make the shape of a query clearer, not produce one line per keyword.
Why a line comment is moved onto a line of its own
A line comment runs to the end of the line, so anything written after it would be commented out. The formatter gives the comment a line of its own and continues the statement underneath, which keeps the SQL valid.
A comment left in the middle of a reflowed line can end up with real tokens pushed past its end. The result is SQL where part of a clause has quietly become comment text: it still parses, and it no longer does what it says. Forcing the comment onto its own line makes that impossible.
Block comments are handled differently, because they end where they end and swallow nothing that follows. They stay inline where you put them, which keeps a short note next to the column it describes.
Both kinds count as tokens and neither is discarded. The tool reflows whitespace and keyword case; it does not edit your comments, and it never treats a comment as a reason to drop the line it came from.
Converting GROUP_CONCAT and the separator that cannot be left out
PostgreSQL has no GROUP_CONCAT, only string_agg, whose separator is a required argument. MySQL’s default separator is a comma, so GROUP_CONCAT(x) becomes string_agg(x, ‘,’), while an explicit SEPARATOR is carried over as written.
This is one conversion the tool will make on its own, because the rewrite is equivalent rather than merely plausible. It knows which default it is standing in for and writes that default out explicitly, which is exactly what PostgreSQL insists on.
The reverse direction is just as deliberate. A string_agg whose separator is a comma is turned back into a plain GROUP_CONCAT, since the comma is the MySQL default and spelling it out adds nothing. Any other separator becomes a SEPARATOR clause, because that does carry information.
Other substitutions in the same family are decided the same way. IFNULL becomes COALESCE on the way to PostgreSQL, because the two are the same function under different names, and NOW() becomes datetime(‘now’) on the way to SQLite, which has no NOW function. Each is a rewrite with exactly one reading, and each is listed with its before and after text.
The same double quote means two different things in MySQL and PostgreSQL
Under the default MySQL sql_mode, "x" is a string; in PostgreSQL "x" is an identifier, a column or table name. So SELECT "hello" has to be rewritten as 'hello' when converting from MySQL to PostgreSQL, or the meaning changes completely.
This is a semantic difference, not formatting. MySQL uses double quotes for strings, and single quotes work too; PostgreSQL uses double quotes only for identifiers and requires single quotes for strings. The same SQL means different things on the two, while looking identical.
This page rewrites by meaning rather than by character: SELECT "hello" AS a is left alone for mysql to mysql, and becomes 'hello' for mysql to postgres. Going the other way, a double-quoted identifier is not treated as a string.
Why it deserves its own section: the reverse mistake is silent. Treat a PostgreSQL "col" as a string and the query still runs, but a column reference has become a constant, so the results are wrong without any error. That is the hardest class of bug in a database migration.
Because of differences like this, formatting is split into what can be determined and what is guessed: the determinable is converted and explained, the undeterminable is left untouched. Layout only changes whitespace and keyword case, never meaning.
Frequently asked questions
Does formatting change what my SQL does?
No. The formatter only moves whitespace and upper-cases reserved words — it never adds, removes or reorders a token. That is enforced by a test that re-tokenizes the formatted output and demands the same token sequence as the input, so a missing space can never slip through.
Why does it warn instead of translating some things?
Because some differences need to know what you meant. MySQL || is logical OR; in PostgreSQL the same symbols concatenate. MySQL "abc" is a string, in PostgreSQL it is a column name. There is no rewrite that is correct for both readings, so the tool refuses to pick one and tells you instead.
Is MySQL LIMIT 50, 25 the same as LIMIT 25 OFFSET 50?
Yes. MySQL accepts LIMIT offset, row_count as a shorthand; PostgreSQL and SQLite only accept LIMIT row_count OFFSET offset. The tool rewrites the shorthand into the standard form when you convert away from MySQL.
What about ON DUPLICATE KEY UPDATE and ON CONFLICT?
They are not equivalent, so they are flagged rather than converted. ON CONFLICT takes a conflict target — the columns or constraint that trigger the merge — and that cannot be derived from an ON DUPLICATE KEY statement, which relies on whatever unique indexes happen to exist. You have to name the target yourself.
Can it convert stored procedures or full schema dumps?
Not reliably. Procedures, triggers and vendor-specific DDL carry far more dialect detail than a formatter can track, and a wrong rewrite there is expensive. Use it on queries and simple DDL, and treat everything it lists under “needs your hand” as genuinely requiring your judgement.
Does it send my queries anywhere?
No. The whole thing is plain JavaScript running in the page — no server, no request, no logging. It also works offline once loaded, which is a reasonable way to check that claim yourself.
Related tools
Test a regular expression against your own text, see every match and capture group highlighted, get each piece of the pattern explained, and check what JavaScript, PCRE and RE2 actually support. Everything runs in your browser.
Paste JSON, YAML or TOML and get the other two back, with syntax errors pinned to the exact line and column. Runs entirely in your browser — nothing you paste is uploaded.
Work out the network address, broadcast address, host range and mask of any IPv4 or IPv6 CIDR — and check whether an IP belongs to it. Nothing leaves your browser.