I'm trying to write binary data into bytea
column in PostgreSQL table. My data contains null characters and I get following error.
ValueError: A string literal cannot contain NUL (0x00) characters.
This is my 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))
id
is of type text
and v
is of type bytea
.
I have also tried using psycopg.Binary(blob)
, but it inserts backslashes which I don't want.