Skip to content

convert

Transform SQL dumps between different database dialects.

Alias: cv (e.g., sql-splitter cv mysql.sql --to postgres -o pg.sql)

  • Database migration - Moving from MySQL to PostgreSQL (or any other combination)
  • Cross-platform development - Convert production dumps to SQLite for local testing
  • Cloud migration - Transform on-premise SQL Server dumps for cloud PostgreSQL
  • Tool compatibility - Convert between dialects when tools only support specific formats

Use validate after conversion to verify the output is valid for your target database.

The converter parses the source dump, transforms DDL (CREATE TABLE, indexes, constraints) and DML (INSERT, COPY) statements to the target dialect. This includes:

  • Identifier quoting - Backticks (MySQL) ↔ double quotes (PostgreSQL/SQLite) ↔ brackets (MSSQL)
  • Data types - Maps 50+ types between dialects (e.g., AUTO_INCREMENTSERIAL)
  • Bulk import syntax - Converts PostgreSQL COPY ... FROM stdin to INSERT statements for other dialects
  • String escaping - Adapts escape sequences between dialects
Terminal window
sql-splitter convert <INPUT> --to <DIALECT> [OPTIONS]
Terminal window
# MySQL to PostgreSQL
sql-splitter convert mysql.sql --to postgres -o pg.sql
# PostgreSQL to MySQL (COPY blocks become INSERT statements)
sql-splitter convert pg_dump.sql --to mysql -o mysql.sql
# Any dialect to SQLite (great for local development)
sql-splitter convert dump.sql --to sqlite -o sqlite.sql

Auto-detection works in most cases, but you can specify the source explicitly:

Terminal window
# When auto-detection fails or you want to be explicit
sql-splitter convert dump.sql --from mssql --to mysql -o mysql.sql

Use --strict to fail on any unsupported features instead of emitting warnings:

Terminal window
sql-splitter convert dump.sql --to postgres --strict

Pipe the converted output directly into your database client:

Terminal window
# Convert and restore in one step
sql-splitter convert mysql.sql.gz --to postgres -o - | psql "$PG_CONN"
# Convert and load into SQLite
sql-splitter convert pg_dump.sql --to sqlite -o - | sqlite3 dev.db
FlagShortDescriptionDefault
--output-oOutput SQL file or directorystdout
--fromSource dialect: mysql, postgres, sqlite, mssqlauto-detect
--toTarget dialect (required)-
--strictFail on any unsupported featurefalse
--progress-pShow progress barfalse
--dry-runPreview without writing filesfalse
--fail-fastStop on first error (for glob patterns)false
--jsonOutput results as JSONfalse

All 12 conversion pairs are supported:

  • MySQL ↔ PostgreSQL (including COPY → INSERT)
  • MySQL ↔ SQLite
  • MySQL ↔ MSSQL
  • PostgreSQL ↔ SQLite
  • PostgreSQL ↔ MSSQL
  • SQLite ↔ MSSQL

50+ data type mappings are handled automatically:

MySQLPostgreSQLSQLiteMSSQL
INT AUTO_INCREMENTSERIALINTEGER PRIMARY KEYINT IDENTITY
TINYINT(1)BOOLEANINTEGERBIT
VARCHAR(n)VARCHAR(n)TEXTNVARCHAR(n)
DATETIMETIMESTAMPTEXTDATETIME2
TEXTTEXTTEXTNVARCHAR(MAX)
BLOBBYTEABLOBVARBINARY(MAX)

PostgreSQL’s COPY ... FROM stdin format is converted to INSERT statements:

-- Input (PostgreSQL)
COPY users (id, name) FROM stdin;
1 Alice
2 Bob
\.
-- Output (MySQL)
INSERT INTO users (id, name) VALUES (1, 'Alice');
INSERT INTO users (id, name) VALUES (2, 'Bob');

The conversion continues successfully even when encountering unsupported features - they generate warnings but don’t stop the process.

These types are converted to the closest equivalent, with a warning:

FeatureConverted ToNotes
MySQL ENUM('a','b','c')VARCHAR(255) (PostgreSQL/MSSQL) or TEXT (SQLite)Enum values are lost; consider adding CHECK constraints manually
PostgreSQL arrays (INT[])JSON (MySQL), TEXT (SQLite), NVARCHAR(MAX) (MSSQL)Data format preserved as JSON string

These statements are omitted from the output (with a warning):

  • CREATE TRIGGER - Trigger syntax is too dialect-specific to convert
  • CREATE PROCEDURE / CREATE FUNCTION - Stored procedure logic cannot be automatically translated
  • CREATE TYPE - Custom types have no equivalent in most dialects
  • CREATE DOMAIN - PostgreSQL-specific
  • CREATE EXTENSION - PostgreSQL-specific
  • CREATE SEQUENCE - Skipped because SERIAL/BIGSERIAL columns are converted to AUTO_INCREMENT/IDENTITY, which handle sequencing automatically
  • COMMENT ON - Not supported in all dialects

The command outputs a count of skipped statements at the end. Use --strict to fail instead of skipping.

See Type Mappings Reference for the complete list of 50+ type conversions.

If conversion fails completely (not just warnings), check:

  1. Syntax errors in source dump - Validate first: sql-splitter validate dump.sql
  2. Wrong source dialect detected - Specify explicitly: --from mysql
  3. Malformed statements - The error message includes the problematic statement

The converter preserves statement order from the input. If your dump has non-deterministic ordering (e.g., mysqldump without --order-by-primary, or tables listed in different order each time):

Terminal window
# Sort the dump first for stable, reproducible output
sql-splitter order dump.sql -o ordered.sql
sql-splitter convert ordered.sql --to postgres -o pg.sql

This is especially important for CI where you want to detect actual changes, not ordering noise.

Force the source dialect explicitly:

Terminal window
sql-splitter convert ambiguous.sql --from mysql --to postgres -o pg.sql
  1. Validate the output: sql-splitter validate pg.sql --dialect postgres
  2. Check for unsupported features: Re-run with --strict to see all warnings
  3. Check type mappings: See Type Mappings Reference for dialect-specific details