Antoine Wako
Antoine Wako

Reputation: 145

Import sql file invalid byte sequence for encoding "UTF8": 0x80

i try to import a SQL file in my Rails app with postgresql database but when i run ActiveRecord::Base.connection.execute(IO.read("tmp/FILE.SQL"))

I got this error (PG::CharacterNotInRepertoire: ERROR: invalid byte sequence for encoding "UTF8": 0x80

I never found answer here with 0x80 error code When i check with file command i got this Non-ISO extended-ASCII text, with very long lines (334), with CRLF line terminators

I can't change the sql file because it's from client so parsing of the file without import can be another solution if the problem from the file

Upvotes: 0

Views: 178

Answers (1)

Lorin Thwaits
Lorin Thwaits

Reputation: 409

Any chance that your data has the Euro symbol within? Character 0x80 is € in Win-1252 character set. If that's what's going on then try this method of converting to UTF-8:

ActiveRecord::Base.connection.execute(File.read('tmp/FILE.SQL', encoding: 'cp1252').encode('utf-8'))

Upvotes: 1

Related Questions