MySQL → PostgreSQL
Convert MySQL AUTO_INCREMENT to PostgreSQL sequences
PostgreSQL implements auto-numbering with sequences (or the newer identity columns). A correct migration also restarts the counter above your existing ids.
AUTO_INCREMENT → sequence / identity
What to know
- id INT AUTO_INCREMENT PRIMARY KEY → integer + sequence default (or GENERATED … AS IDENTITY)
- The sequence is reset with setval() to max(id)+1, so new inserts don't collide
- LAST_INSERT_ID() becomes RETURNING id — cleaner and race-free
- Our converter resets every sequence automatically after the data load
Before / after
MySQL
CREATE TABLE users (
id INT UNSIGNED NOT NULL AUTO_INCREMENT,
PRIMARY KEY (id)
); PostgreSQL
CREATE TABLE users (
id bigint GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY
);
-- INSERT … RETURNING id; Don't convert column-by-column — convert the whole database.
Upload a dump, get back ready-to-import SQL with this mapping (and every other one) applied.
Open the MySQL → PostgreSQL converterSee the full type mapping table or all guides.