[sqlalchemy] Aggregating results of a union

2013-03-21 Thread Alexey Vihorev
Hi! I have this query: q1 = (s.query() .add_columns( Movement.customer_id, Movement.document_id, func.sum(Movement.debt).label('debt_moved'),

Re: [sqlalchemy] Aggregating results of a union

2013-03-21 Thread Ladislav Lenart
Hello. Perhaps something like this is what you are looking for? def q_union(): s = session q1 = s.query( Movement.customer_id.label('customer_id'), Movement.document_id.label('document_id'), Movement.debt.label('debt_moved'),

Re: [sqlalchemy] Aggregating results of a union

2013-03-21 Thread Ladislav Lenart
As usual, I forgot to add the attachment... Ladislav Lenart On 21.3.2013 13:57, Ladislav Lenart wrote: Hello. Perhaps something like this is what you are looking for? def q_union(): s = session q1 = s.query( Movement.customer_id.label('customer_id'),

[sqlalchemy] joinedload + limit

2013-03-21 Thread Jose Neto
Given the following statement: p = db.query(Profile).options(joinedload('*')).filter_by(id=p.id).limit(1).one() I will get a subquery + a join, instead of a pure join: SELECT [...] FROM (SELECT profile.id AS profile_id, ...FROM profile WHERE profile.id = %(id_1)s LIMIT %(param_1)s) AS

Re: [sqlalchemy] joinedload + limit

2013-03-21 Thread Simon King
On 21 Mar 2013, at 20:56, Jose Neto jbastosn...@gmail.com wrote: Given the following statement: p = db.query(Profile).options(joinedload('*')).filter_by(id=p.id).limit(1).one() I will get a subquery + a join, instead of a pure join: SELECT [...] FROM (SELECT profile.id AS