title: Unable to convert PostgreSQL text column to bytea
body: <p>In my application I am using a postgresql database table with a "text" column to store
  pickled python objects.
  As database driver I'm using psycopg2 and until now I only passed python-strings (not unicode-objects) to the DB and retrieved strings from the DB. This basically worked fine until I recently decided to make String-handling the better/correct way and added the following construct to my DB-layer:</p>
  
  <pre><code>psycopg2.extensions.register_type(psycopg2.extensions.UNICODE)
  psycopg2.extensions.register_type(psycopg2.extensions.UNICODEARRAY)
  </code></pre>
  
  <p>This basically works fine everywhere in my application and I'm using unicode-objects where possible now.</p>
  
  <p>But for this special case with the text-column containing the pickled objects it makes troubles. I got it working in my test-system this way:</p>
  
  <ul>
  <li>retrieving the data: 
  <code>SELECT data::bytea, params FROM mytable </code></li>
  <li>writing the data:
  <code>execute("UPDATE mytable SET data=%s", (psycopg2.Binary(cPickle.dumps(x)),) )</code></li>
  </ul>
  
  <p>... but unfortunately I'm getting errors with the SELECT for some columns in the production-system:</p>
  
  <pre><code>psycopg2.DataError: invalid input syntax for type bytea
  </code></pre>
  
  <p>This error also happens when I try to run the query in the psql shell.</p>
  
  <p>Basically I'm planning to convert the column from "text" to "bytea", but the error
  above also prevents me from doing this conversion.</p>
  
  <p>As far as I can see, (when retrieving the column as pure python string) there are only characters with ord(c)&lt;=127 in the string.</p>