我怎么知道我是否成功创建了一个表(Python、Psycopg2)? [英] How do I know if I have successfully created a table (Python, Psycopg2)?

查看:53
本文介绍了我怎么知道我是否成功创建了一个表(Python、Psycopg2)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我查看了文档,但没有找到任何让我知道我通过 cursor.execute("...") 执行的最后一个命令是否成功的信息.

I've looked at the documentations but haven't found anything that lets me know if the last command i've execute via cursor.execute("...") is successful.

我期待收到类似受影响的 1 行"之类的回复.

I'm expecting a reply like "1 row affected."

推荐答案

我期待某种例外情况.
如果一切顺利 - 错误代码是 00000 并且不会有任何例外.

I'd expect some kind of exception to be risen.
If everything went ok – the error code is 00000 and no exception will get risen.

create table 情况下,您始终可以仔细检查:

In create table case, you can always double check:

try:
    cur.execute("SELECT ouch FROM aargh;")
except Exception, e:
    pass

errorcodes.lookup(e.pgcode[:2])
# 'CLASS_SYNTAX_ERROR_OR_ACCESS_RULE_VIOLATION'
errorcodes.lookup(e.pgcode)
# 'UNDEFINED_TABLE'

这篇关于我怎么知道我是否成功创建了一个表(Python、Psycopg2)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆