1

Our DB is going to upgrade from postgresql 8.4 to 9.3 and we are asked to do some verification on our legacy app (Rails 2.3.2 app). (Don't laugh, it's a real app that runs for years). And I use latest pg gem (0.17.1), but it's really big change to move to latest 2.3.18 for rails so I just stay with old rails version.

And one table is storing some binary data (column type is bytea).

Here comes the issue: When I run 8.4 as backend db, that table can get record inserted. when I run 9.3 as backend db, the rails app freak out for "invalid byte sequence for encoding "UTF8" ...

And out db in pg8/9 are all build in UTF8 encoding. And the app code is same.

What I can observe is the SQL generated (logged in test.log) is different: for 8.4:

INSERT INTO "large_keys" ("u_id", "key_value", "key_hash", "created_at", "type", 
"iv")     VALUES(793287954, E'\\3540\\272\\204\\327H\\204w\\021\\341\\362I\\205\\3456\\252', 
NULL, '2014-02-20 10:32:00.869783', E'aes', E'aaabbbcccddd1234’);

but 9.3:

INSERT INTO "large_keys" ("type", "iv", "key_value", "created_at", "u_id", "key_hash") 
VALUES(E'aes', E'aaabbbcccddd1234', E'\3540\272\204\327H\204w\021\341\362I\205\3456\252', 
'2014-02-20 10:33:46.659190', 793287954, NULL);

The main different is key_value is escaped correctly when talking 8.4. but I don't understand which reason make front-end activerecord to behave different?

Thanks in advance for any idea.

7
  • Oh, just realize stackoverflow eat backslash for the first SQL I pasted. in 8.4, it should be: ... VALUES(793287954, E'\\3540\\272\\204\\327H\\204w\\021\\341\\362I\\205\\3456\\252', NULL, '2014-02-20 10:32:00.869783', E'aes', E'aaabbbcccddd1234’);
    – kyrre
    Feb 20, 2014 at 6:34
  • do these inserts work from postgres directly? Feb 20, 2014 at 6:36
  • no, it's from rails app. And I also ran the 2nd SQL in psql directly and get the same error.
    – kyrre
    Feb 20, 2014 at 6:41
  • Sorry @Kyrre I am bit slow today. Is you question that "8.4 produces double slashes but 9.3 doesn't" ? Feb 20, 2014 at 6:46
  • yes, that's what I am noticing from log file.
    – kyrre
    Feb 20, 2014 at 7:02

0

Your Answer

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

Browse other questions tagged or ask your own question.