我已经编写了一个脚本来更新 psycopg2 中的员工表,但更新没有发生,currr.execute 返回 None 对象。
我的代码
connm = psycopg2.connect(database="database", user = "user", password = "pass", host = "localhost", port = "5432")
connm.autocommit = True
sql = """ UPDATE employee SET name = %s WHERE phone_number = %s"""
curr = connm.cursor()
username = "Mike"
query = "+0123456789"
abc = curr.execute(sql, (username, query))
print abc
connm.commit()
curr.close()
此 abc 对象返回 None。
请帮助我! 提前致谢!
最佳答案
引用"Psycopg – PostgreSQL database adapter for Python - execute command" :
The method returns None. If a query was executed, the returned values can be retrieved using fetch*() methods
然后,无看起来不错。恭喜:)
编辑没有效果:
你能在数据库上测试你的查询吗?
my_raw_query=curr.mogrify(sql, (username, query))
print my_raw_query
检查查询是否正确,然后在数据库上复制粘贴查询以再次检查。
关于python - Psycopg2(curr.execute)返回 NONE python,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47569747/