心理2(当前执行)返回NONE python

2024-09-11 00:39:55 发布

您现在位置:Python中文网/ 问答频道 /正文

我编写了一个脚本来更新psycopg2中的employee表,但是更新没有发生在当前执行返回的对象为“无”。在

我的代码

            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。在

请帮帮我! 提前谢谢!在


Tags: 对象代码脚本sqlconnectusernameemployeepassword
1条回答
网友
1楼 · 发布于 2024-09-11 00:39:55

引用"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

检查查询是否正常,并在数据库上复制粘贴查询以再次检查。在

相关问题 更多 >