title: MySQL's HEX() and UNHEX() equivalent in Postgres?
body: <p>I'm in the process of converting some tools over that are using MySQL to PostgreSQL. With that, I've run into a number of issues but was able to find most everything. The one I'm having an issue with is <code>HEX()</code> and <code>UNHEX()</code>. I've tried <code>encode(%s, 'hex')</code> and <code>decode(%s, 'hex')</code> which did actually stop causing me to have errors, but it still did not seem to do the trick. Does anyone have an idea to what the equivalent of those functions would be in Postgres?</p>
  
  <p>Here is the old MySQL query:</p>
  
  <pre><code>SELECT HEX(test_table.hash),
         title,
         user,
         reason,
         description,
         url,
         performed,
         comment,
         authenticated,
         status
  FROM alerts
  JOIN user_responses ON test_table.hash = user_responses.hash
  JOIN test_status ON test_table.hash = test_status.hash
  WHERE status = %s
  </code></pre>
  
  <p>And here is my updated query in PostgreSQL format:</p>
  
  <pre><code>SELECT encode(test_table.hash, 'hex') as hash,
         title,
         user,
         reason,
         description,
         url,
         performed,
         comment,
         authenticated,
         status
  FROM test_table
  JOIN user_responses ON test_table.hash = user_responses.hash
  JOIN test_status ON test_table.hash = test_status.hash
  WHERE status = %s
  </code></pre>
  
  <p>Thanks!</p>