0

I'm running a PostGreSQL query and when I print it, this is returned: [{'sum': 117L}]

Here is the code itself:

cursor.execute("SELECT SUM(length) FROM carmileage")
totalLength = cursor.fetchall()
print totalLength

How would I format this into a number without the (what appears to be) surrounding JSON?

winseybash
  • 664
  • 1
  • 12
  • 26
  • Also see this - http://stackoverflow.com/questions/11764713/why-do-integers-in-database-row-tuple-have-an-l-suffix – Bulat Aug 06 '15 at 15:23

1 Answers1

1

Simply iterate through your resultset. Cursors pass rows in SQL select queries into Python lists:

cursor.execute("SELECT SUM(length) FROM carmileage")
totalLength = cursor.fetchall()

for row in totalLength:
    print(row)
Parfait
  • 97,543
  • 17
  • 91
  • 116