0

I try to insert data in exist table:

img_query = "INSERT INTO images (img_name) VALUES ({}) RETURNING id".format(img)
img_id = self.engine.execute(img_query)

I use sqlalchemy engine for execution. As a result received this type of mistakes:

sqlalchemy.exc.ProgrammingError: (psycopg2.errors.SyntaxError) syntax error at or near "_Group_Large_Group_12_Group_Large_Group_12_15"
LINE 1: INSERT INTO images (img_name) VALUES (12_Group_Large_Group_1...

I tried to change "12_" on "12" or replace all "_" on "-". Result not changed I received same error.

1 Answer 1

1

You need to allow psycopg2 to do the quoting for you:

img_query = "INSERT INTO images (img_name) VALUES (%s) RETURNING id;"
img_id = self.engine.execute(img_query,(img,))
Sign up to request clarification or add additional context in comments.

Comments

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.