I seem to have some fundamental mental block about using SA and its objects in my Pylons app. I want to get some counts of rows and MySQL needs a GROUP BY clause to allow it to do a count() so I tried:
q = self.session.query(Fault).select([Fault.c.severity, func.count(Fault.c.severity)], Fault.c.ts_created >= self.this_week, group_by=[Fault.c.severity], ) But this throws: TypeError: select() takes at most 2 non-keyword arguments (3 given) Is there no way to do the extra group_by keywords here? So I follow some examples in the docs -- without the session.* -- and get: q = select([Fault.c.severity, func.count(Fault.c.severity)], Fault.c.ts_created >= self.this_week, group_by=[Fault.c.severity], ) systems = q.execute().fetchall() which works but the result is not an object from my model: systems = [('[escalate to vendor]', 7L)] I was expecting to be able to access attributes from each row like: for system in systems: print system.severity When I think about how to ask for the count, I kinda see why I can't reference it as an object atttribute: how would I request the count for the system, what is the attribute name? Perhaps if I had specified an alias for the resulting count... It also seems I can't use the Result-Set Mapping as per the docs as the result set doesn't have all the attributes it needs to create the model object. Am I being stupid about not seeing the difference -- what keywords and arguments I can use -- between: self.session.query(MyClass).select(...) and select(...) Thanks. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To post to this group, send email to sqlalchemy@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~----------~----~----~----~------~----~------~--~---