I am migrating some data from a MySql database (v5.1.44/MyISAM/collation=latin1_swedish_ci) to a PostgreSQL (v9.0.4/the one included in OSX Lion).
$ mysqldump --compatible=postgresql > tmp.sql # output create/insert statements $ psql --command='\i tmp.sql' # import to postgresql
However the import fails with the error
ERROR: invalid byte sequence for encoding "UTF8": 0xe97261 (This is in reference to accented letters).
The issue, I think, being that the exported file is not using utf-8.
The file that is exported shows the following file information
$ file tmp.sql tmp.sql: Non-ISO extended-ASCII text, with very long lines
What's the easiest, scriptable way to get this file prepared in utf-8 for psql?
This does not work:
$ iconv -f ASCII -t UTF-8 tmp.sql > out.sql iconv: tmp.sql:18:59270: cannot convert
I've found that opening the file in
vim and issuing
:set fenc=utf-8 does make the import run smoothly, but this has to be automated so I need to cut out this manual step.