我正在运行PostGreSQL查询,当我打印它时,会返回:[{'sum': 117L}]
以下是代码本身:
cursor.execute("SELECT SUM(length) FROM carmileage")
totalLength = cursor.fetchall()
print totalLength
如果没有围绕JSON的(似乎是什么),我如何将其格式化为数字?
答案 0 :(得分:1)
只需遍历结果集即可。游标将SQL select查询中的行传递到Python列表中:
cursor.execute("SELECT SUM(length) FROM carmileage")
totalLength = cursor.fetchall()
for row in totalLength:
print(row)