gpt4 book ai didi

python - Psycopg2(curr.execute)返回 NONE python

转载 作者:太空宇宙 更新时间:2023-11-03 14:26:53 24 4
gpt4 key购买 nike

我已经编写了一个脚本来更新 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com