The Ruby Craftsman
Postgres Regex Parsing
For some reason a Ruby array of BigDecimals was being inserted into a String column in our Portgres DB. With a lot of trying out different things and some help from another software developer and DBA we came up with a solution to parse out the numbers. The goal was to convert a string of ["83000.0", "119000.0"]
to an PG array {83000.0, 119000.0}
. It Take some regex, but it’s doable.
Breaking apart the parts:
Clean up string and remove square brackets.
Split string into array by comma
Conclusion
I would’nt recommend this for use in production, but works great for some ad hoc querying.