在使用python的psycops2时,用sql语句向postgresql中插入数据时,有可能会遇到无法插入的情况。
看代码
cur.execute("""
insert into final_test (id,data)
values (1,now())
""")
print(cur.fetchall())
报错:
ProgrammingError: no results to fetch
国内很难搜到解决方法
目前发现一个方法:
INSERT
在查询语句的最后,加上returning *,一方面会返回当前被插的表格,一方面就不会报错了。我也不知道为啥,反正就是可以用了。
如果只想返回某一列,把*号改了就行