Ask A Question

Notifications

You’re not receiving notifications from this thread.

Store a hash in a database

David Field asked in Databases

I have a calculator that takes yearly pension contributions into a hash. Therefore, everyone has a contribution lined up with a year. I don't want a database of dozens of years as one individuals contributions my start in 1970 while another's in 2000. I basically just want to keep the data stored in the hash it currently is in (I currently don't store this information in a database). Is hstore the best thing to look at or serialize or something else? Thank you in advance for all input.

Reply

A json or jsonb column can save/load a hash pretty easily and sounds like it might work for what you need. I'd just be careful to store simple things like strings, numbers, arrays in it and not something like a Ruby object.

Reply

Thank you for pointing me in this new direction.

Reply
Join the discussion
Create an account Log in

Want to stay up-to-date with Ruby on Rails?

Join 87,563+ developers who get early access to new tutorials, screencasts, articles, and more.

    We care about the protection of your data. Read our Privacy Policy.