- changed status to wontfix
func.sum on MySQL returns type 'str' when it should be returning type 'int'
Issue #239
resolved
On any table with an integer column, sum() on that column should return an integer. But it returns a string!
My code that demonstrates this is:
create table simple (
id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
license_uri VARCHAR(255) NOT NULL,
search_engine VARCHAR(255) NOT NULL,
count INT NOT NULL,
timestamp DATETIME NOT NULL,
country VARCHAR(255),
language VARCHAR(255)
);
# Set up data
from sqlalchemy.ext.sqlsoup import SqlSoup
from sqlalchemy import *
db = SqlSoup('mysql://root:@localhost/cc')
s = select([db.simple.c.timestamp](func.sum(db.simple.c.count),))
s.group_by(db.simple.c.timestamp)
all = s.fetchall()
one = s[0](0)
sum_result = one[0](0) # zeroth based on the select() arguments
assert(type(s.fetchone()[0](0) == type(0) # This will fail
I tested on official sqlalchemy 0.2.4 and Debian 0.2.5-0.1. The problem exists on both.
Comments (1)
-
repo owner - Log in to comment
this is a problem with MySQL/MySQLdb. just trying it with straight DBAPI i cannot get an integer out of this no matter what I try:
plus straight CAST throws an error, etc. MySQL not too good at stuff.