Reputation: 33
I have an account table database which stores username, email, password and images[]. And what I want to do that every time they share a picture the picture bytes should append in images type bytea[]. I used several methods but always ends up with an error what is the solution?
bytea = []
my_cursor = mydb.cursor()
with open(os.path.join('image\\Image.png'), 'rb') as file:
image = file.read()
#bytea.append(image)
insert_info = f"SELECT array_append(images, {image}) WHERE id = 7"
my_cursor.execute(insert_info)
mydb.commit()
The error
psycopg2.errors.SyntaxError: syntax error at or near "("
LINE 1: SELECT account array_append(images, b'\x89PNG\r\n\x1a\n\x00\...
Upvotes: 0
Views: 515
Reputation: 113
you must write select rather than insert :
bytea = []
my_cursor = mydb.cursor()
with open(os.path.join('image\\Image.png'), 'rb') as file:
image = file.read()
bytea.append(image)
insert_info = f"insert array_append(images, {image}) WHERE id = 7"
my_cursor.execute(insert_info)
mydb.commit()
Upvotes: 1