SQL Dialect Converter
Move a query or schema from one database to another. The SQL is rewritten for the target dialect, with a list of every change so you can review it. The quick reference below covers the differences that break most migrations.
Conversion uses an AI model (sent only when you click). Max 8,000 characters. Check the result with the SQL validator.
Syntax differences at a glance
| Task | MySQL | PostgreSQL | SQL Server | SQLite | Oracle |
|---|---|---|---|---|---|
| Quote an identifier | `name` | "name" | [name] | "name" | "NAME" |
| First 10 rows | LIMIT 10 | LIMIT 10 | TOP (10) | LIMIT 10 | FETCH FIRST 10 ROWS ONLY |
| Skip 20, take 10 | LIMIT 20, 10 | LIMIT 10 OFFSET 20 | OFFSET 20 ROWS FETCH NEXT 10 ROWS ONLY | LIMIT 10 OFFSET 20 | OFFSET 20 ROWS FETCH NEXT 10 ROWS ONLY |
| Auto-increment key | INT AUTO_INCREMENT | INT GENERATED ALWAYS AS IDENTITY | INT IDENTITY(1,1) | INTEGER PRIMARY KEY | NUMBER GENERATED AS IDENTITY |
| Boolean column | TINYINT(1) / BOOLEAN | BOOLEAN | BIT | INTEGER | NUMBER(1) / BOOLEAN (23ai) |
| Concatenate | CONCAT(a, b) | a || b | a + b / CONCAT(a, b) | a || b | a || b |
| NULL fallback | IFNULL(x, 0) | COALESCE(x, 0) | ISNULL(x, 0) | IFNULL(x, 0) | NVL(x, 0) |
| Current timestamp | NOW() | now() | SYSDATETIME() | datetime('now') | SYSTIMESTAMP |
| Add 7 days | DATE_ADD(d, INTERVAL 7 DAY) | d + INTERVAL '7 days' | DATEADD(day, 7, d) | date(d, '+7 days') | d + 7 |
| Upsert | ON DUPLICATE KEY UPDATE | ON CONFLICT (k) DO UPDATE | MERGE | ON CONFLICT (k) DO UPDATE | MERGE |
| Return inserted id | LAST_INSERT_ID() | RETURNING id | OUTPUT inserted.id | RETURNING id | RETURNING id INTO :v |
| Case-insensitive match | LIKE (collation-dependent) | ILIKE | LIKE (collation-dependent) | LIKE (ASCII only) | UPPER(a) LIKE UPPER(b) |
A migration checklist
- Schema first. Convert types (see SQL data types), identity columns, defaults and constraints. Character sets matter: MySQL
utf8is not full UTF-8, so useutf8mb4. - Then queries. Quoting, paging, upserts and date arithmetic cause most breakage.
- Watch semantics, not just syntax. Empty string vs NULL in Oracle, case-sensitivity of comparisons, integer division (
5/2is 2 in PostgreSQL and SQL Server, 2.5 in MySQL). - Validate per dialect with the dialect checkers: PostgreSQL, MySQL, SQL Server, SQLite.
Questions
How do I convert MySQL to PostgreSQL?
Change backticks to double quotes, AUTO_INCREMENT to GENERATED … AS IDENTITY (or SERIAL), TINYINT(1) to BOOLEAN, DATETIME to TIMESTAMP, LIMIT x, y to LIMIT y OFFSET x, IFNULL to COALESCE, and ON DUPLICATE KEY UPDATE to ON CONFLICT … DO UPDATE. Paste your SQL above to have it rewritten with a list of each change; for whole databases use a migration tool such as pgloader.
Can SQL be converted automatically between databases?
Most of it, yes: quoting, types, LIMIT/TOP and common functions map cleanly. Some features have no direct equivalent (MySQL ENUM, SQL Server MERGE options, PostgreSQL arrays), and stored procedures differ completely. That is why every change is listed for you to review.
Is my SQL stored?
No. The SQL is sent once to an AI model through Vercel AI Gateway to produce the conversion and is not stored by DiagramDB. The reference table on this page works without sending anything.
What about converting a schema rather than a query?
For CREATE TABLE statements you can also use the DBML editor: paste SQL into “SQL → DBML”, then convert the DBML to PostgreSQL, MySQL, SQL Server or SQLite. That conversion runs entirely in your browser.
Related tools
- SQL ValidatorCheck syntax for MySQL, PostgreSQL, SQL Server, SQLite and BigQuery, with the exact line and column.
- DBML EditorWrite DBML with a live diagram, convert DBML to SQL and back.
- SQL Data TypesThe same type across MySQL, PostgreSQL, SQL Server, Oracle and SQLite.
- Text to SQLDescribe what you want in plain English and get a query that uses your real schema.