title: Storing binary objects in postgres using Ruby on Rails
body: <p>I need to store JSON-like objects in our postgres DB.
  Originally I was just using serialized fields but they were
  consuming too much space. So I wrote a simple custom compression
  scheme and am now using Marshal.dump/load to access the data.
  But I hit a snag with postgres' bytea field type - it's insisting
  that every non-visible byte be encoded as a 3-digit octal number, e.g. '\377'.</p>
  
  <p><a href="http://www.postgresql.org/docs/8.1/static/datatype-binary.html" rel="noreferrer">http://www.postgresql.org/docs/8.1/static/datatype-binary.html</a></p>
  
  <p>I can't see an easy way to achieve this.
  s.pack( "m#{s.size}" )
  seems to generate strings with single '\' whereas postgres wants '\'.
  Adding a gsub( /\/, '\\\\' ) on the end doesn't seem to solve it.</p>
  
  <p>Does anyone have a more elegant (and working) solution?</p>