Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ActiveRecord::StatementInvalid: PG::CharacterNotInRepertoire: ERROR: invalid byte sequence for encoding "UTF8": 0x92 #16

Closed
brain64bit opened this issue May 18, 2014 · 1 comment

Comments

@brain64bit
Copy link

i've a csv file, when i check using unix file command, for example :

file -b --mime data.csv

its return text/plain; charset=us-ascii

But when i try to import using postgres-copy i've an exception :

ActiveRecord::StatementInvalid: PG::CharacterNotInRepertoire: ERROR:  invalid byte sequence for encoding "UTF8": 0x92 

how do i set a character encoding before import a csv to the database ?

@diogob
Copy link
Owner

diogob commented Jul 30, 2014

You should set the client_encoding in the PostgreSQL connection.
I believe you can set this in the options when you open the connection (should be in database.yml in rails apps).

But if your database is in UTF-8 then this won't work (because PostgreSQL will still try to read your data and convert to the DB encoding) and the best approach will be to clean the file and get rid of invalid UTF-8 byte sequences.

@diogob diogob closed this as completed Jul 30, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants