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
  • 704
  • 2
  • 12
  • 27
  • 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
  • 104,375
  • 17
  • 94
  • 125