VillageSQL is a drop-in replacement for MySQL with extensions.
All examples in this guide work on VillageSQL. Install Now →
Data Type Mapping
Sequences vs AUTO_INCREMENT
PostgreSQL uses sequences (independent objects) for auto-increment values. MySQL usesAUTO_INCREMENT as a column attribute:
PostgreSQL:
SELECT LAST_INSERT_ID(); (equivalent to PostgreSQL’s currval() or RETURNING id).
SQL Dialect Differences
String concatenation:ANSI_QUOTES SQL mode is enabled.
ILIKE (case-insensitive LIKE):
utf8mb4_general_ci or similar collations. If you need case-sensitive matching, use a _bin collation.
RETURNING clause:
mydb.public.orders). MySQL uses “schemas” and “databases” interchangeably — there’s no concept of a schema within a database. What PostgreSQL calls a schema, MySQL calls a database.
NULL handling in UNIQUE indexes:
PostgreSQL allows multiple NULL values in a unique column (NULLs are not equal to each other). MySQL (InnoDB) also allows multiple NULLs in unique indexes — behavior is the same.
CTEs:
MySQL supports CTEs including recursive CTEs. See CTEs in MySQL.
Window functions:
MySQL supports window functions. See Window Functions in MySQL.
Features Without MySQL Equivalents
Some PostgreSQL features have no direct equivalent:Migration Approach
- Export the schema from PostgreSQL (
pg_dump --schema-only) and translate each table manually, using the type mapping above. - Export the data from PostgreSQL as CSV (
COPY table TO '/tmp/table.csv' CSV HEADER). - Load the data into MySQL with
LOAD DATA INFILEormysqlimport. - Test queries — find all PostgreSQL-specific syntax and rewrite it.
- Verify counts and checksums —
SELECT COUNT(*)on every table; spot-check key rows.
Frequently Asked Questions
Does MySQL support UPSERT like PostgreSQL’s ON CONFLICT?
Yes, using different syntax. See UPSERT in MySQL. MySQL’s INSERT ... ON DUPLICATE KEY UPDATE and REPLACE INTO cover the same use case as PostgreSQL’s ON CONFLICT DO UPDATE and ON CONFLICT DO NOTHING.
How do I handle PostgreSQL’s BOOLEAN columns in MySQL?
Use TINYINT(1). Store 1 for true and 0 for false. Most MySQL client libraries and ORMs handle this automatically and present TINYINT(1) columns as booleans. You can also use BIT(1) but TINYINT(1) has broader tooling support.
Troubleshooting
See also
- Schema Migrations in MySQL — running the DDL changes a migration requires
- Choosing MySQL Data Types — mapping PostgreSQL types to MySQL equivalents

