title: inserting brokenly formatted text into PostgreSQL table despite encoding errors with \copy
body: <p>I have a text field (utf8) that misbehaves a little. originally fetched it includes the character sequence <code>\u00e2\u0080\u0099</code> which is basically an apostrophe in another encoding. I have decided to maintain this corrupted state and not solve it despite the fact I have found a few solutions online on how to reinterpret these kinds of errors in my text field.</p>
  <p>So I just want to insert the raw data as is.
  I have tried 2 ways to insert this row.</p>
  <ol>
  <li>Using python with peewee (an orm library).
  with everything configured correctly this method actually works, the data is inserted and
  there is a row in the database.<br />
  selecting the column yield: <code>don├ó\u0080\u0099t</code>
  which I am ok with keeping.</li>
  </ol>
  <p>So far so good.</p>
  <ol start="2">
  <li>Writing a python script that prints tab delimited text and using \copy<br />
  Annoyingly this method does not work and returns the following error:</li>
  </ol>
  <pre><code>ERROR:  invalid byte sequence for encoding &quot;UTF8&quot;: 0x80
  CONTEXT:  COPY comment, line 1: &quot;'donâ\x80\x99t'&quot;
  </code></pre>
  <p>(when printing the data from the python script to console it shows up as <code>donâ\x80\x99t</code>)</p>
  <p>Thus clearly there is a difference between what peewee does and my naive printing of the string from python (peewee and print receive the same string as input).</p>
  <p>How do I encode this string correctly so I can use \copy to populate the row?</p>