I'm trying to use some of the agg functions in MySQLdb (avg, min, max),
but they're just not working as I would expect. They all return the
value 1 when executed as part of Python scripts, but work as expected
when used in mysql 4.1. Does anyone have any experience using Python
with MySQLdb? Quite frankly, the more I use it, the more MySQLdb seems
to be not quite ready for prime time.
--
"My Break-Dancing days are over, but there's always the Funky Chicken"
--The Full Monty 5 1212
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,)
Thanks, that was my problem. Can you point me to some documentation on
MySQLdb? I've been googling to get answers and that obviously has not
been working.
In article <11*********************@v46g2000cwv.googlegroups. com>,
"Wade Leftwich" <wl*******@gmail.com> wrote: 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,)
Lorenzo Thurman wrote: Thanks, that was my problem. Can you point me to some documentation on MySQLdb? I've been googling to get answers and that obviously has not been working.
I've been looking into this too lately, and finding thorough docs for it
is hard. Have you seen these yet: http://sourceforge.net/docman/?group_id=22307
In article <Fi******************@news.tufts.edu>,
John Salerno <jo******@NOSPAMgmail.com> wrote: http://sourceforge.net/docman/?group_id=22307
Yes, I did, but I did not find them thorough enough.
--
"My Break-Dancing days are over, but there's always the Funky Chicken"
--The Full Monty
In article <nn********************************@4ax.com>,
Dennis Lee Bieber <wl*****@ix.netcom.com> wrote: On Mon, 15 May 2006 20:14:29 GMT, John Salerno <jo******@NOSPAMgmail.com> declaimed the following in comp.lang.python:
Lorenzo Thurman wrote: Thanks, that was my problem. Can you point me to some documentation on MySQLdb? I've been googling to get answers and that obviously has not been working.
I've been looking into this too lately, and finding thorough docs for it is hard. Have you seen these yet: http://sourceforge.net/docman/?group_id=22307
For the most part, it follows the DB-API 2 specifications. The subject of this thread (aggregates) would have occurred with ANY db-api compliant adapter, even plain ODBC -- since it was a misunderstanding that xxxx.execute() returns the status code (typically # of records affected by the query), and xxxx.fetchnnn() is needed to obtain the data values. This misunderstanding is not specific to use of aggregates as any "select..." statement functions this way.
Most divergences from the db-api specifications should be determinable by looking at the sources of the python portion of the adapter; or by looking at the features of the underlying RDBM.
Thanks, you are correct. I have done similar database things using PHP
and Perl to connect to databases, and I felt like DUH, when I got my
first reply, but there are times when one cannot see the forest for the
trees, so to speak. Better docs can help.
--
"My Break-Dancing days are over, but there's always the Funky Chicken"
--The Full Monty This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Dave Harrison |
last post by:
Hi all, got a problem combinging mx and MySQLdb, when I build and install both for my Python2.1 install on a Solaris 9 box I can import mx fine, but importing MySQLdb causing python to core dump.
...
|
by: Chris Stromberger |
last post by:
When issuing updates in mysql (in the console window), mysql will tell
you if any rows matched and how many rows were updated (see below). I
know how to get number of rows udpated using MySQLdb,...
|
by: Peter Nikolaidis |
last post by:
Greetings,
I am attempting to get MySQLdb 0.9.2 installed on Mac OS 10.2 with a
Fink distribution of Python 2.2.2. I have seen only a few posts on the
subject, some of them relate to...
|
by: Derek Fountain |
last post by:
I was trying to use MySQLdb to connect to a database. All is OK, except I
can't figure out how to get the details of an error. Suppose I try to
connect to a non existant server, or with the wrong...
|
by: Tim Williams |
last post by:
I'm trying to write a simple python program to access a MySQL
database. I'm having a problem with using MySQLdb to get the results
of a SQL command in a cursor. Sometimes the cursor.execute works,...
|
by: ws Wang |
last post by:
MySQLdb is working fine at command line, however when I tried to use
it with mod_python, it give me a "server not initialized" error.
This is working fine:
----------------------- testmy.py...
|
by: Steve |
last post by:
Darwin steve.local 8.3.0 Darwin Kernel Version 8.3.0: Mon Oct 3
20:04:04 PDT 2005; root:xnu-792.6.22.obj~2/RELEASE_PPC Power Macintosh
powerpc
MacOSX 10.4.3
mysql Ver 14.7 Distrib 4.1.14, for...
|
by: Yi Xing |
last post by:
Hi,
I met the following error when I tried to install MySQLdb. I had no
problem installing numarray, Numeric, Rpy, etc. Does anyone know
what's the problem? Thanks!
running install
running...
|
by: Steve Holden |
last post by:
Vaibhav.bhawsar wrote:
imported
The point here is that MySQLdb is a package, not a module. Some packages
have their top-level __init__.py import the package's sub-modules or
sub-packages to...
|
by: DolphinDB |
last post by:
Tired of spending countless mintues downsampling your data? Look no further!
In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: Vimpel783 |
last post by:
Hello!
Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
|
by: ArrayDB |
last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Defcon1945 |
last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
| |