Hmmm, it translates on its own 1 to True like this: "SELECT count(*) FROM direccionesgrupo WHERE direccionesgrupo.activo='T';" Which results in 58 rows
Whereas if it does "SELECT count(*) FROM direccionesgrupo WHERE direccionesgrupo.activo=1;" Then result is 112 MySQL seems to take anything it doesnt understand as a 0 and returns all the values = 0. (If instead of 'T' I enter any other char value still gets the ceroes as if it was retreiving false values). True or false are like SELECT count(*) FROM direccionesgrupo WHERE activo=TRUE; or SELECT count(*) FROM direccionesgrupo WHERE activo=FALSE; for MySQL. Which are actually just aliases TRUE for 1, FALSE for 0. Probably need to change the SELECT generated to 1 or 0, or not change value from 1 to 'T' on its own. If instead of ==1 I use ==True, same result (though I guess you are aware of that). db(db.direccionesgrupo.activo==True)._select('count(*)') Out[3]: "SELECT count(*) FROM direccionesgrupo WHERE direccionesgrupo.activo='T';" On Dec 10, 5:38 pm, mdipierro <mdipie...@cs.depaul.edu> wrote: > print > > db(db.direccionesgrupo.activo==1)._select('count(*)') > > do you see anything wrong in the generated sql? > > On Dec 10, 9:48 am, Benigno <bca...@albendas.com> wrote: > > > In the table this is taken from, activo is either 1 or 0. In the table > > which is legacy MySQL it is defined as INT(1) > > > These are the results I am getting: > > > In [46]: db(db.direccionesgrupo.activo == 1).count() > > Out[46]: 58L > > > In [48]: a =db().select(db.direccionesgrupo.activo.sum()) > > > In [49]: print a > > -------> print(a) > > SUM(direccionesgrupo.activo) > > 112 > > > In [51]: b = db(db.direccionesgrupo.activo==1).select('count(*)') > > > In [52]: print b > > -------> print(b) > > count(*) > > 58 > > > The correct value is the one done with the aggregate sum(). -- You received this message because you are subscribed to the Google Groups "web2py-users" group. To post to this group, send email to web...@googlegroups.com. To unsubscribe from this group, send email to web2py+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/web2py?hl=en.