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

标签 python sql psycopg2 psql

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

相关文章:

sql - 重新创建一组表同时保持它们可用的最佳实践?

psycopg2 - 为什么 psycopg2 不允许我们在同一连接中打开多个服务器端游标?

python - 自定义 postgres 范围类型的 SQLalchemy 表示

python - 从 celery 中撤销任务

带有 ttk 日历的 Python tkinter

python - 查看之前的命令是否仍在 PyCharm IPython 控制台中运行?

python - 根据bp坐标提取fasta序列的一部分

c# - ServiceStack ORMLite UpdateOnly 故障

php - 当使用 PHP 查询我的 MySQL 数据库时,如何解决这个 undefined index 错误?

postgresql - 使用 pyscopg2 和 PostgreSQL 将日期时间插入数据库