Ok, I figured it out. stmt = session.query(Bill).filter_by(account_id=id).order_by(Bill.timestamp.desc()).subquery() session.query().add_entity(Bill, alias=stmt).group_by(Bill.date_begin)
On Monday, March 17, 2014 7:44:09 PM UTC-7, Jonathan Herriott wrote: > > Hi, > > I was creating a billing table that needs to be updated on repeated cycles > as more information becomes available for a month, so I was following an > Add Only scheme where I only add new rows, so we can keep track of the > history of the month. Now, when I show them a list of bills for the year, > I only want to show them the most up to date for each month, so initially, > I was doing something like: > > > session.query(Bill).filter_by(account_id=id).order_by(Bill.timestamp.desc()).group_by(Bill.date_begin) > > Unfortunately, this doesn't compile a query in the read order or something > comparable. Second, I tried: > > stmt = > session.query(Bill).filter_by(account_id=id).order_by(Bill.timestamp.desc()).subquery() > session.query(stmt).group_by(Bill.date_begin) > > This does get me the correct result, however, the problem is, for > backwards compatibility, this does not actually return a list of Bill > objects, but instead, it returns a list of KeyedTuples. Is there a way to > achieve what I want with sqlalchemy? > > Thanks, > Jon > -- You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To unsubscribe from this group and stop receiving emails from it, send an email to sqlalchemy+unsubscr...@googlegroups.com. To post to this group, send email to sqlalchemy@googlegroups.com. Visit this group at http://groups.google.com/group/sqlalchemy. For more options, visit https://groups.google.com/d/optout.