title: How to write null characters to a bytea column using psycopg2 in Python
body: <p>I'm trying to write binary data into <code>bytea</code> column in PostgreSQL table. My data contains null characters and I get following error.</p>
  
  <pre><code>ValueError: A string literal cannot contain NUL (0x00) characters.
  </code></pre>
  
  <p>This is my code.</p>
  
  <pre><code>import numpy as np
  fft = [0.0, 0.2, 0.0215]
  [float(i) for i in fft]
  blob = struct.pack('%sd' % np.size(fft), *fft)
  cur.execute("""INSERT INTO fft (id, v) VALUES(%s, %s)""", ("widget_fft", blob))
  </code></pre>
  
  <p><code>id</code> is of type <code>text</code> and <code>v</code> is of type <code>bytea</code>.</p>
  
  <p>I have also tried using <code>psycopg.Binary(blob)</code>, but it inserts backslashes which I don't want.</p>