I am using MySQL 5.0.7. I am using Python 2.4.2. I am
using MySQLdb 1.1.6-1ubuntu2 (installed through apt on
Ubuntu Linux 5.04).
1) Create a table similar to this...
comment varchar(255) default NULL,
group int(10) unsigned NOT NULL
2) Insert a row similar to this...
gctest VALUES ('test',1);
3) Execute the following SELECT in a Python program...
SELECT GROUP_CONCAT(comment) AS comment FROM gctest
group ORDER BY comment;
db = MySQLdb.connect(host="localhost", user="",
cursor = db.cursor()
cursor.execute("SELECT GROUP_CONCAT(comment) AS comment
FROM gctest GROUP BY
group ORDER BY comment;")
for record in cursor.fetchall():
4) Observe the results...
This indicates that an array of some sort is being
returned. I don't know the significance of its contents
in the Python world, but it means that while all other
elements in the resultset are returned as strings, this
one bizarre exception exists.
I was able to narrow my test case down to the behavior
occurring when GROUP BY and ORDER BY appear in the same
statement AND they reference different columns. That
is, when the results are GROUPped BY one column and
ORDERed BY another, this behavior occurs.
I don't reproduce it either with this query on my
original dataset (with the addition of a column
containing the value 6 (arbitrary):
mysql> select * from gctest;
| comment | group | id |
| test | 1 | 6 |
Here is the query i used:
select sum(id) as x from gctest group by
It simply returned "6", as one would hope it would do.
Perhaps interesting is the fact that this doesn't cause
any "problem" either (returns 'testtest'):
SELECT CONCAT(comment,comment) AS comment FROM gctest
group ORDER BY
While not using the aggregate function in the field
list, it does still use the other elements. This must
mean that the problem is related to the aggregate
function, and more specifically to GROUP_CONCAT since
the problem is not triggered by SUM().
It seems like it is probably an issue with the MySQLdb