Can I store arrays in hstore with Rails -


i want save data this:

user.create(name:"guy", properties:{url:["url1","url2","url3"], street_address:"asdf"})

can in rails 4? far, have tried migration: add_column :users, :properties, :hstore, array: true

but when save array in hstore, returns error:

pg::invalidtextrepresentation: error: array value must start "{" or dimension information

hstore intended simple key/value storage, both keys , values simple unstructured strings. fine manual:

f.16. hstore

this module implements store data type storing sets of key/value pairs within single postgresql value. [...] keys , values text strings.

note last sentence: keys , values in hstore strings. means can't put array in hstore value without handholding convert array , string , don't want messing around sort of thing.

however, there json data type available:

8.14. json type

the json data type can used store json (javascript object notation) data, specified in rfc 4627.

and json can handle embedded arrays , objects. try using json instead:

add_column :users, :properties, :json 

you'll have remove old hstore column first though.

also, didn't want array: true on hstore column weren't storing array of hstores, wanted 1 of them.


Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -