0

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\...
2
  • 2
    You're SELECTing not INSERTing or UPDATEing; This >>>insert_info = f"SELECT array_append(images, {image}) WHERE id = 7" should be this >>>insert_info = f"UPDATE array_append(images, {image}) WHERE id = 7" Commented Sep 7, 2021 at 1:03
  • Its hits me with an error psycopg2.errors.SyntaxError: syntax error at or near "(" Commented Sep 12, 2021 at 22:02

1 Answer 1

1

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()
Sign up to request clarification or add additional context in comments.

1 Comment

I used the script above but still here is the error psycopg2.errors.SyntaxError: syntax error at or near "array_append" LINE 1: INSERT array_append(images, 'b'\x89PNG\r\n\x1a\n\x00\x00\x00...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.