0

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

1
  • What is the output of file tmp/FILE.sql? Commented Jul 31, 2022 at 21:43

1 Answer 1

1

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'))
Sign up to request clarification or add additional context in comments.

1 Comment

Sorry for late reply, it works now i have syntax error with "`"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.