Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/306.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 插入psycopg2.errors.SyntaxError_Python_Postgresql_Sqlalchemy - Fatal编程技术网

Python 插入psycopg2.errors.SyntaxError

Python 插入psycopg2.errors.SyntaxError,python,postgresql,sqlalchemy,Python,Postgresql,Sqlalchemy,我尝试在exist表中插入数据: img_query = "INSERT INTO images (img_name) VALUES ({}) RETURNING id".format(img) img_id = self.engine.execute(img_query) 我使用sqlalchemy引擎执行。 因此,我们收到了此类错误: sqlalchemy.exc.ProgrammingError: (psycopg2.errors.SyntaxError) syntax error a

我尝试在exist表中插入数据:

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

我使用sqlalchemy引擎执行。 因此,我们收到了此类错误:

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...


我试着把“12”改成“12”,或者把“-”上的所有“u”都换掉。结果未更改我收到了相同的错误。

您需要允许psycopg2为您进行报价:

img_query = "INSERT INTO images (img_name) VALUES (%s) RETURNING id;"
img_id = self.engine.execute(img_query,(img,))