encoding issues with postgresql array-of-hstore columns #11135

inopinatus opened this Issue Jun 27, 2013 · 16 comments


None yet

inopinatus commented Jun 27, 2013

With the new postgresql magic, we can create arrays of hstore columns but they don't quite work due to incorrect encoding, storing values throws the following error from the database:

ActiveRecord::StatementInvalid: PG::Error: ERROR:  malformed array literal

Which is a pity because being able to store an array of arbitrary key,value pairs seems terribly useful.

Demo at https://gist.github.com/inopinatus/5930884 which barfs at line 57 (where it says "boom!"), and fix that works for me in pull request #11444

+1 This needs some TLC

rpearce commented Dec 20, 2013



inopinatus commented Jan 9, 2014

Well, I've rebased the PR twice now. I'll do it again iff someone with privileges will offer to actually merge it.


hiro-su commented Jan 13, 2014



rafaelfranca commented Jan 17, 2014

The pull request now is #13512


inopinatus commented Jan 20, 2014

+1 as OP, hereby endorsing new PR #13512


axilaris commented Mar 3, 2014

can someone tell me how do i apply this patch ? I have the same error but not sure what should i do to apply this patch. I am using rails 4.0.2


zzak commented Mar 3, 2014

This should be fixed by #13512

axilaris commented Mar 3, 2014

ok got it working, just this:
gem 'rails', git: 'https://github.com/inopinatus/rails', branch: 'hstore_arrays_fix'

i wonder if this would work on heroku for example ? do they allow versions of rails not in the official releases.


robin850 commented Mar 3, 2014

@axilaris : You can actually rely on the 4-0-stable branch of the rails/rails repository or upgrade to version 4.1.0.rc1.

@zzak is right ; this issue should not be there anymore since #13512 has been merged. Thank you guys!

@robin850 robin850 closed this Mar 3, 2014


chancancode commented Mar 3, 2014

Hey @axilaris, this patch was written before 4.0.3 was released, which contains a security fix for postgres arrays. Since you are using that feature, it's highly recommend that you apply that security patch. The fork/branch you linked does not contain the patch so it's not advisable to use that in production, especially if you rely on the PG array feature.

If you are on the 4.0.x series and you need this patch, you should use the 4-0-stable branch as Robin suggested (gem 'rails', github: 'rails/rails', branch: '4-0-stable') which has the patch applied as well as the sec fix. When 4.0.4 is released, you can simply upgrade to that version.

If you are on the 4.1.x series you can use 4.1.0.rc1 as Robin pointed out. (The branch you linked is closer to 4.1.x than 4.0.x.)

axilaris commented Mar 3, 2014

thanks all for your advises. tested with the following and it worked.
gem 'rails', github: 'rails/rails', branch: '4-0-stable'

will upgrade when 4.0.4 is officially released.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment