On Nov 21, 2013, at 6:32 AM, Chris Withers <ch...@simplistix.co.uk> wrote:

> 
> Yep, in fact ended up with:
> 
> positions = session.query(Part.instrument_id, 
> func.sum(Part.quantity).label("quantity"))\
>       .filter((Part.account_id=='td') & (Part.timestamp < date(2013, 11, 1)))\
>       .group_by(Part.instrument_id)\
>       .having(func.sum(Part.quantity)!=0).cte('positions')
> 
> ...which left me wondering, if I had the query asL
> 
> query = """
> select instrument_id, sum(quantity) as quantity
>        from transaction where
>            account_id = :account_id and
>            timestamp < :dt and
>        group by instrument_id
>        having sum(quantity) != 0
> """
> 
> How could I combine that string with values for account_id and dt into a cte? 
> I'm expecting something involving text(), but I can't figure out the right 
> incantation…

hoping you’ve already figured it out but otherwise I’m not entirely following 
what the larger query you’re looking for would look like.    I doubt you need 
text() for anything.

Attachment: signature.asc
Description: Message signed with OpenPGP using GPGMail

Reply via email to