【发布时间】:2013-10-12 01:46:54
【问题描述】:
获取此查询返回的数字或行的正确方法是什么?我特别想看看是否没有返回结果。
sql = 'SELECT count(*) from table WHERE guid = %s;'
data=[guid]
cur.execute(sql,data)
results = cur.fetchone()
for r in results:
print type(r) # Returns as string {'count': 0L} Or {'count': 1L}
谢谢。
【问题讨论】:
-
count 将只返回 1 行(在这种情况下)
-
type(r)将不会返回为{'count': 0L}。它很可能会打印<type 'dict'>或类似的。 -
type(r) 返回 {'count': 0L} 直接来自控制台。
标签: python postgresql psycopg2