All threads / Store a hash in a database

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.

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.

Thank you for pointing me in this new direction.

Join the discussion

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

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

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

    logo Created with Sketch.

    Ruby on Rails tutorials, guides, and screencasts for web developers learning Ruby, Rails, Javascript, Turbolinks, Stimulus.js, Vue.js, and more. Icons by Icons8

    © 2021 GoRails, LLC. All rights reserved.