wtznga
Last Updated: February 25, 2016
·
1.55K
· jacaetevha
D21ebccf20562e370eb0a8cf170a0580

Convert Postgres tables to Ruby hashes

This may not be readily useable, but...

With Postgres' hstore type you can convert tables into Ruby hashes almost natively. With a little bit of tweaking in Ruby it's drop-dead simple.

Person.find_by_sql("SELECT '{' || regexp_replace(hstore(t)::varchar,'NULL','nil', 'g') || '}' FROM people as t").map do |p|
  eval p.hstore
end
Say Thanks
Respond