returning results of sql select count

This is the place for queries that don't fit in any of the other categories.

returning results of sql select count

Postby droidus » Wed Apr 02, 2014 12:32 am

I am returning results of a sql query:
Code: Select all
cursor = cnx.cursor()
cursor.execute("SELECT COUNT(*) from members where username!='sandy'")
result=cursor.fetchone()
print(result)

When this is executed, I get (2,). I would expect 2. Why did it return it in this format?
droidus
 
Posts: 1
Joined: Mon Mar 31, 2014 1:49 pm

Re: returning results of sql select count

Postby stranac » Wed Apr 02, 2014 8:34 am

Consistency.
The fetch* methods always return selected rows as tuples, or None if there are no results.
Friendship is magic!

R.I.P. Tracy M. You will be missed.
User avatar
stranac
 
Posts: 1246
Joined: Thu Feb 07, 2013 3:42 pm


Return to General Coding Help

Who is online

Users browsing this forum: fri3ndlygiant, Google [Bot], ichabod801, Yoriz and 3 guests