The blog has moved to http://jessehouse.com/ ... Many google searches point here so I am leaving it operational, but there will be no new posts.

Thursday, April 23, 2009

PGError: ERROR: invalid byte sequence for encoding "UTF8": 0xa7 (ActiveRecord::StatementInvalid)

Working on a rails application and have decided to make the switch from MySql to Postgresql; ran into a few minor issues along the way and one really annoying and unexpected issue

PGError: ERROR: invalid byte sequence for encoding "UTF8": 0xa7 (ActiveRecord::StatementInvalid)
HINT: This error can also happen if the byte sequence does not match the encoding expected by the server, which is controlled by "client_encoding".


The above error was being generated when I was trying to save model objects that had their string and text attributes assigned from data that had been scrapped using http with scRUBYt. After searching on Google the only 'work-around' I found was to use base64 encode and decode when reading and writing to these model attributes / database columns

Given the following migration

Our model before and then after applying the work-around


Resources

1 comment:

House 9 said...

Had an issue with comment moderation
------------------------------------

Justin Ko posted the following about a month ago
---------
The last solution on this post also works.
http://blogs.jetthoughts.com/blog/2009/12/16/postgresql-insert-not-valid-unicode-values/