As per the title says, I have inserted into my postgresql db a bunch of images that added into an array and used cursor to send to the db. The column in the db is bytea[], so it worked for me.
I used this code snippet to conver the image bytestream into binary, put it into an array and send to db
somearray.append(psycopg2.Binary(image.content))
But when running a select statement to get that array from the database, what i got back was a memoryview, which I'm not sure at this point how to convert it back to an array.
I'm really lost at this point after researching, as most posts tells me to use toByte() to convert the memoryview to some byte string, but my goal is to convert the memoryview into an array or binary items to convert back the binaries into images.
open('target_file.jpg','wb+).write(memory_view_obj)to do that (file.writecan take a memory view object, it doesn't need to be converted into bytes first). What do you plan on doing with the bytes?cursor.execute("select byte_array from test"); image_sets = [row[0] for row in cursor.fetchall()]; images_as_bytes = [bytes(image) for image_array in image_sets for image in image_array];