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.
asked May 22, 2020 at 19:50
Ivan Pozniak
1211 silver badge15 bronze badges
1 Answer 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,))
answered May 22, 2020 at 20:09
mechanical_meat
171k25 gold badges238 silver badges231 bronze badges
Sign up to request clarification or add additional context in comments.
Comments
default