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.

asked May 22, 2020 at 19:50

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,))
answered May 22, 2020 at 20:09
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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.