Aggregate funuctions broken in MySQLdb?
Wade Leftwich
wleftwich at gmail.com
Sun May 14 12:10:11 EDT 2006
Works fine for me, and I certainly hope MySQLdb is ready for prime
time, because I use the heck out of it. Maybe you're getting fooled by
the fact that cursor.execute() returns the count of result rows. To
actually see the result rows, you have to say cursor.fetchone() or
fetchall() --
In [34]: cur.execute("select article_id from articles limit 10")
Out[34]: 10L
In [35]: cur.fetchall()
Out[35]: ((3L,), (4L,), (5L,), (6L,), (7L,), (8L,), (9L,), (10L,),
(11L,), (12L,))
In [36]: cur.execute("select count(article_id) from articles where
article_id < 13")
Out[36]: 1L
In [37]: cur.fetchall()
Out[37]: ((10L,),)
In [38]: cur.execute("select sum(article_id) from articles where
article_id < 13")
Out[38]: 1L
In [39]: cur.fetchone()
Out[39]: (75.0,)
In [40]: cur.execute("select avg(article_id) from articles where
article_id < 13")
Out[40]: 1L
In [41]: cur.fetchone()
Out[41]: (7.5,)
More information about the Python-list
mailing list