ramamoorthy_villi
ramamoorthy_villi

Reputation: 2055

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

The existing solutions for this question not helps.

Rails: 5.2 ruby : 2.4.1 pg: 0.18

This is the query from the rails log: 
INSERT INTO "users" ("first_name") VALUES ('\xC3\r\x04\t\x03\x02qlF\xA4\.....')

first_name value is encrypted using active_record-pgcrypto gem

first_name is string datatype in users table

copy paste the query in pgAdmin works well. But the application throw the error.

Upvotes: 0

Views: 770

Answers (1)

Schwern
Schwern

Reputation: 164679

As mentioned in the pgcrypto install documentation encrypted data should use a :binary column. Otherwise Rails and Postgres will interpret it as UTF-8 characters, and some combinations of bytes are not valid UTF-8 characters.

Upvotes: 1

Related Questions