Skip to content
gohacks.dev
Databases

MySQL to PostgreSQL Schema Converter

Convert MySQL CREATE TABLE statements to PostgreSQL: AUTO_INCREMENT to identity, TINYINT(1) to BOOLEAN, ENUM to CHECK, KEY to CREATE INDEX and FULLTEXT to GIN.

Free · No sign-up · Your inputs stay in your browser

Input

Convert MySQL CREATE TABLE to PostgreSQL

Output

PostgreSQL DDL

1 table, 1 to review

AUTO_INCREMENT becomes an identity column, TINYINT(1) BOOLEAN, DATETIME TIMESTAMP, TIMESTAMP TIMESTAMPTZ, JSON JSONB, ENUM a TEXT column with a CHECK, inline KEYs separate CREATE INDEX statements and FULLTEXT a GIN index over to_tsvector. Data does not move with the schema: pgloader does both for a real migration.

Runs in this browser. Nothing you paste is sent to a server.

The mappings that need thought

PostgreSQL has no unsigned integers, so BIGINT UNSIGNED becomes NUMERIC(20) unless you know the values fit in BIGINT. TIMESTAMP becomes TIMESTAMPTZ, which stores an absolute instant; DATETIME becomes TIMESTAMP without a zone, matching MySQL's behaviour. JSON becomes JSONB, which is indexable but drops duplicate keys and key order.

Schema is the easy half

Moving the data, rewriting MySQL-specific SQL (backtick quoting, LIMIT x, y, GROUP BY looseness, IFNULL) and testing the application is most of a migration. pgloader moves schema and data in one pass and is the usual tool for the whole job.

Share

Frequently asked questions

How do I replace ON UPDATE CURRENT_TIMESTAMP in PostgreSQL?
With a trigger that sets NEW.updated_at = now() before update, or by letting the application set it, as Laravel's Eloquent does for updated_at.
Is MySQL's ENUM supported in PostgreSQL?
PostgreSQL has CREATE TYPE ... AS ENUM, but values are hard to remove or reorder later. A TEXT column with a CHECK constraint, as generated here, is easier to change.
Is what I paste sent anywhere?
No. The tool runs entirely in your browser with JavaScript. Nothing you type or paste is sent to our server or stored.

Keep planning

Similar tools