这是我的 python 代码,用于通过读取 csv 文件执行更新操作。我也试过这个。它行不通。
for i in cin:
try:
conn=psycopg2.connect("dbname=pharmaflare user=postgres")
cursor=conn.cursor()
cursor.execute("UPDATE pharmaflare_drug_interaction SET se_interaction ='%s' WHERE primary_drug ='%s' AND secondary_drug ='%s' AND side_effect ='%s'"%(i[3],i[0],i[1],i[2]))
conn.commit()
cursor.close()
conn.close()
#print "done",i[0],i[1],i[2],i[3]
except Exception as e:
cerr.writerow(i)
ferr.flush()
traceback.print_exc(file=sys.stdout)
continue
由于 QUOTE 的问题,我在这里面临语法错误等异常:无论单引号出现在哪里,都会出现此异常。
Traceback (most recent call last):
File "<ipython console>", line 5, in <module>
ProgrammingError: syntax error at or near "S"
LINE 1: ...secondary_drug ='NEUER' AND side_effect ='MENIERE'S DISEASE'
是否有任何替代方法可用于定义查询语句而不会困扰 Quotes 问题?