Re: [sqlalchemy] creating a cte from a string and some params

2013-12-01 Thread Chris Withers
Cool :-) When's 0.9 due for release? Chris On 29/11/2013 20:17, Michael Bayer wrote: here you go, give it a spin: http://docs.sqlalchemy.org/en/rel_0_9/changelog/migration_09.html#new-text-capabilities On Nov 29, 2013, at 12:13 PM, Michael Bayer mike...@zzzcomputing.com wrote: here’s a

Re: [sqlalchemy] creating a cte from a string and some params

2013-11-29 Thread Chris Withers
On 29/11/2013 05:09, Michael Bayer wrote: On Nov 28, 2013, at 7:54 PM, Chris Withers ch...@simplistix.co.uk wrote: So far, I got: inst = aliased(Part) unit = aliased(Part) query = session.query( inst.idea_id, inst.instrument_id, func.sum(inst.quantity),

Re: [sqlalchemy] creating a cte from a string and some params

2013-11-29 Thread Michael Bayer
Sure i don't mind an enhancement to text(), a method like as_subquery(c1, c2 ...) that turns it into a FromClause On Nov 29, 2013, at 4:20 AM, Chris Withers ch...@simplistix.co.uk wrote: On 29/11/2013 05:09, Michael Bayer wrote: On Nov 28, 2013, at 7:54 PM, Chris Withers

Re: [sqlalchemy] creating a cte from a string and some params

2013-11-29 Thread Michael Bayer
here’s a patch: http://www.sqlalchemy.org/trac/ticket/2877 it’s quite short. I just don’t like the current contract of SelectBase, which has many methods that don’t apply here, so might want to rework the base classes. On Nov 22, 2013, at 5:06 AM, Chris Withers ch...@simplistix.co.uk

Re: [sqlalchemy] creating a cte from a string and some params

2013-11-29 Thread Michael Bayer
here you go, give it a spin: http://docs.sqlalchemy.org/en/rel_0_9/changelog/migration_09.html#new-text-capabilities On Nov 29, 2013, at 12:13 PM, Michael Bayer mike...@zzzcomputing.com wrote: here’s a patch: http://www.sqlalchemy.org/trac/ticket/2877 it’s quite short. I just don’t

Re: [sqlalchemy] creating a cte from a string and some params

2013-11-28 Thread Chris Withers
Hi Mike, Happy Thanksgiving :-) On 22/11/2013 15:55, Michael Bayer wrote: I don't *need* to ;-) ...but I was wondering how, starting with a raw string and a couple of variables to bind in, I could get a cte that I could join against an ORM-mapped object? uh well we don’t exactly have

Re: [sqlalchemy] creating a cte from a string and some params

2013-11-28 Thread Michael Bayer
On Nov 28, 2013, at 7:54 PM, Chris Withers ch...@simplistix.co.uk wrote: So far, I got: inst = aliased(Part) unit = aliased(Part) query = session.query( inst.idea_id, inst.instrument_id, func.sum(inst.quantity),

Re: [sqlalchemy] creating a cte from a string and some params

2013-11-22 Thread Chris Withers
On 21/11/2013 19:25, Michael Bayer wrote: 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. Okay, pseudo code that doesn't work: positions = something( select

Re: [sqlalchemy] creating a cte from a string and some params

2013-11-22 Thread Michael Bayer
On Nov 22, 2013, at 5:06 AM, Chris Withers ch...@simplistix.co.uk wrote: On 21/11/2013 19:25, Michael Bayer wrote: 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

Re: [sqlalchemy] creating a cte from a string and some params

2013-11-22 Thread Chris Withers
On 22/11/2013 15:23, Michael Bayer wrote: (this latter query will likely have more stuff in it, not sure I used .select_from(...).join(...) correctly either ;-) Hope that illustrates what I'm after… take your original cte and use it just like that, just call positions.c.instrument_id for

Re: [sqlalchemy] creating a cte from a string and some params

2013-11-22 Thread Michael Bayer
On Nov 22, 2013, at 10:31 AM, Chris Withers ch...@simplistix.co.uk wrote: On 22/11/2013 15:23, Michael Bayer wrote: (this latter query will likely have more stuff in it, not sure I used .select_from(...).join(...) correctly either ;-) Hope that illustrates what I'm after… take your

Re: [sqlalchemy] creating a cte from a string and some params

2013-11-21 Thread Chris Withers
On 19/11/2013 23:36, Michael Bayer wrote: you want to label your func.sum() in the CTE: positions = session.query(Instrument, func.sum(Part.quantity).label(quantity))\ then refer to quantity and instrument_id using .c. since positions is now a core CTE element: session.query(Instrument,

Re: [sqlalchemy] creating a cte from a string and some params

2013-11-21 Thread Michael Bayer
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)))\