通过psycopg2插入Postgres返回语法错误

时间:2018-12-18 00:33:19

标签: python python-3.x postgresql psycopg2

我正在尝试使用变量将数据插入到postgres表中。在查看了有关该主题的其他答案后,这似乎很简单,但是在我有机会将其插入数据库之前,我从python中收到语法错误

我正在使用的execute语句:

cur.execute("""INSERT INTO "public"."catalogue_product" ("id","structure","upc","title","slug","description","rating","date_created","date_updated","is_discountable","parent_id","product_class_id","collection_id","multiplier","dimension","feat1","feat10","feat2","feat3","feat4","feat5","feat6","feat7","feat8","feat9","image_url","price","short_name","sku") VALUES (nextval'catalogue_product_id_seq'::regclass),'standalone',NULL,%s,'noslug',%s,NULL,current_timestamp,current_timestamp,TRUE,NULL,NULL,NULL,'2.2',%s,'','','','','','','','','','',%s,%s,%s,%s)""", (name, desc, dimension, imageurl, price, shortname, sku))

据我所知,所有括号和引号都应匹配。

可能是什么原因造成的?

编辑:按照下面的回答,我改用三重引号(并编辑了上面的代码以反映出来),这似乎有所帮助,但仍然出现错误:

psycopg2.ProgrammingError: syntax error at or near "'standalone'"
LINE 1: ...ES (nextval'catalogue_product_id_seq'::regclass), 'standalon...

1 个答案:

答案 0 :(得分:1)

您还有一个额外的),它太早关闭了VALUES列表:

... ::regclass),'standalone' ...
          THIS^
相关问题