python - 使用 psycopg2 出现 InternalError 后要怎么处理?
大家讲道理
大家讲道理 2017-04-17 11:39:12
[Python讨论组]

执行完第 6 行以后,再怎么执行都抛出 InternalError.

请问有没有办法执行完第 6 行后还能继续查询?

1  import psycopg2
2  conn = psycopg2.connect("dbname=test user=test")
3  cur = conn.cursor()
4  cur.execute("select phone from account where phone = %s;", ("13366668888",))
5  cur.fetchone()
6  cur.execute("select phone from account where phone = %s;", (13366668888,))
7  cur.execute("select phone from account where phone = %s;", ("13366668888",))

输出如下(省略了 Traceback):

Out[5]: ('13366668888',)

Out[6]: ProgrammingError: operator does not exist: character varying = bigint
LINE 1: select phone from account where phone = 13366668888;
                                              ^
HINT:  No operator matches the given name and argument type(s). You might need to add explicit type casts.

Out[7]: InternalError: current transaction is aborted, commands ignored until end of transaction block
大家讲道理
大家讲道理

光阴似箭催人老,日月如移越少年。

全部回复(2)
阿神

current transaction is aborted, commands ignored until end of transaction block

中文就是

当前事务被中止,直到事务结束前的命令都将被忽略

所以你想继续的话,开启新事务就可以了,比如 conn.commit() 一下。

PHP中文网

猜测应该是psycopg2的实现把execute的语句当作事务来处理了.

Note: Some client libraries issue BEGIN and COMMIT commands automatically, so that you might get the effect of transaction blocks without asking. Check the documentation for the interface you are using.

所以当某条语句执行失败后

当前事务被中止,直到事务结束前的命令都将被忽略

热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习
PHP中文网抖音号
发现有趣的

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号