Hi, I'm trying to get aggregation functions to work as column_properties, but I'm having a hard time figuring it out. The example below doesnt work.. maybe someone can help?
ratings = Table('ratings', metadata, Column('rating_key', Integer, primary_key=True), Column('user_id', Integer, primary_key=True), Column('rating', SmallInteger, default=0) ) class Rating(object): pass mapper(Rating,ratings, properties = { 'count' : column_property( select([func.count (ratings.c.id)],ratings.c.id==ratings.c.id)), 'average': column_property( select([func.avg (ratings.c.rating)],ratings.c.id==ratings.c.id)) } ) Test data: sql.insert(ratings).execute([{'rating_key':1,'user_id':1,'rating':5}, {'rating_key':1,'user_id':2,'rating':4}, {'rating_key': 2,'user_id':1,'rating':1}, {'rating_key':3,'user_id':1,'rating':1}, {'rating_key':3,'user_id':2,'rating':1}, {'rating_key':3,'user_id':3,'rating':4},]) r = s.query(Rating).filter_by(rating_key=1,user_id=1).first() desired result: r.rating_key = 1 r_user_id = 1 r.rating = 5 r.average = 4.5 #averate all users for rating_key 1 r.count = 2 #rating count (users) for rating_key 1 thanks Bj --~--~---------~--~----~------------~-------~--~----~ 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 sqlalchemy+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~----------~----~----~----~------~----~------~--~---