wtznga
Last Updated: February 25, 2016
·
1.565K
· jacaetevha

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