PostgreSQL → MySQL
Convert PostgreSQL arrays to MySQL
MySQL has no array types. The faithful, queryable mapping is a JSON array — '{a,b}' becomes ["a","b"] and MySQL's JSON functions take over.
text[] / integer[] → JSON
What to know
- Any array type → JSON; element values are preserved
- 'x' = ANY(tags) becomes JSON_CONTAINS(tags, '"x"')
- array_length(tags,1) becomes JSON_LENGTH(tags)
- Multi-dimensional arrays nest as JSON arrays of arrays
Before / after
PostgreSQL
SELECT * FROM accounts WHERE 'vip' = ANY(tags); MySQL
SELECT * FROM accounts WHERE JSON_CONTAINS(tags, '"vip"'); 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 PostgreSQL → MySQL converterSee the full type mapping table or all guides.