title: bytea in postgres storing and retrieving bytes
body: <p>I am trying to understand how to work with binary data in postgresql (v 8.3).
  Let's say I have a following table</p>
  
  <pre><code>Table "public.message"
  Column  |  Type   | Modifiers 
  ---------+---------+-----------
  id      | integer | 
  message | bytea   | 
  </code></pre>
  
  <p>I would like to store a packet in the message field in this format:</p>
  
  <p>version (1 byte), identifier (1 byte), epoch (4 bytes)</p>
  
  <p>I would like to pack this data into the message field. Lets say I have version=1, identifier=8 and epoch=123456. How would I pack this data into the message field? How would I convert my integer values to hex.. or octal?</p>
  
  <p>I also need to get the message back and parse it. I was looking at the <code>get_byte</code> function, unless there is another way to parse the data out..</p>
  
  <p>Thanks!</p>