MySQL → PostgreSQL
Convert MySQL INT UNSIGNED to PostgreSQL
PostgreSQL has no unsigned integers. An UNSIGNED column can hold values above the signed maximum, so it must be widened to the next larger type to stay lossless.
INT UNSIGNED → bigint
What to know
- INT UNSIGNED → bigint (max 4,294,967,295 doesn't fit signed integer)
- SMALLINT UNSIGNED → integer, BIGINT UNSIGNED → numeric(20,0)
- If you know values stay below 2,147,483,647 you can narrow back to integer after import
- CHECK (col >= 0) can be added to keep the non-negative guarantee
Before / after
MySQL
CREATE TABLE hits (
counter INT UNSIGNED NOT NULL
); PostgreSQL
CREATE TABLE hits (
counter bigint NOT NULL CHECK (counter >= 0)
); 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.