Hi All,
I have a few monster queries like this:
query = session.query(
Blah1.name.label('blah1'),
Blah2.name.label('blah2'),
blah3.name.label('blah4'),
Blah5.name.label('blah5'),
Blah6.name.label('blah6'),
func.sum(case([(Blah7.blah8_blah9=='Blah8',Blah10.qty)],
else_=Blah10.qty*-1)).label('blah11'),
func.sum(case([(Blah7.blah8_blah9=='Blah8',Blah10.qty*blah13.price)],
else_=Blah10.qty*blah13.price*-1)).label('blah12')).\
join(Blah1.participents,
Participation.blah5,
Blah5.blah10s,
Blah10.fill,
blah13.blah7,
Blah7.blah6,
Blah7.blah12,
Blah12.blah7_idea,
Blah2.blah4).\
filter(and_(Blah1.id==self.id,
Participation.valid_from <= on_date,
or_(Participation.valid_to > on_date,
Participation.valid_to == None))).\
group_by(Blah6).\
order_by(Blah6.name)
...apologies for the obfuscation.
Now, is there any way I can "pre-cook" this (eg: at module-level) such
that I can later just plug in self.id and on_date, bind to a session and
call .all() on it?
It seems a bit wasteful to do all the SQL generation on every query when
it's almost all identical all the time...
cheers,
Chris
--
Simplistix - Content Management, Batch Processing & Python Consulting
- http://www.simplistix.co.uk
--
You received this message because you are subscribed to the Google Groups
"sqlalchemy" group.
To post to this group, send email to [email protected].
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.