Re: [sqlalchemy] Problem writing a query with distinct

2012-10-24 Thread Ladislav Lenart
Hello. I haven't used distinct() yet, but if you modify your query: query = dbSession.query( Candidate )\ .join( Vote )\ .filter(\ model.core.Candidate.id == model.core.Vote.candidate_id , model.core.Vote.yay == True , )\ .order_by(\

Re: [sqlalchemy] Re: Alembic 0.4.0 Released

2012-10-24 Thread junepeach
Thank you very much, Michael. It is exactly what I need. On Tuesday, October 23, 2012 5:38:36 PM UTC-4, Michael Bayer wrote: that might not be supported yet. it just emits AUTO_INCREMENT for now. Looking at MySQL's docs it seems like you should just emit an ALTER for that explicitly:

[sqlalchemy] [Q] Transform a select part of a query

2012-10-24 Thread Ladislav Lenart
Hello. Suppose I have the following query: def people_older_than(age): q = session.query(Person).order_by(Person.name) q = q.filter(Person.age age) return q It returns a subset of Person instances. How can I augment the query so it returns only their count? I.e.: def

Re: [sqlalchemy] [Q] Transform a select part of a query

2012-10-24 Thread Simon King
On Wed, Oct 24, 2012 at 3:59 PM, Ladislav Lenart lenart...@volny.cz wrote: Hello. Suppose I have the following query: def people_older_than(age): q = session.query(Person).order_by(Person.name) q = q.filter(Person.age age) return q It returns a subset of Person instances.

Re: [sqlalchemy] [Q] Transform a select part of a query

2012-10-24 Thread Ladislav Lenart
Oh, you are right of course. This works, however I would still like to transform the query programmatically (mainly out of curiosity) from q = session.query(Person).order_by(Person.name) q = q.filter(Person.age age) return q to q = session.query(func.count(Person.id))

Re: [sqlalchemy] [Q] Transform a select part of a query

2012-10-24 Thread Michael Bayer
with_entities() will give you this: http://docs.sqlalchemy.org/en/rel_0_7/orm/query.html#sqlalchemy.orm.query.Query.with_entities On Oct 24, 2012, at 11:21 AM, Ladislav Lenart wrote: Oh, you are right of course. This works, however I would still like to transform the query programmatically

Re: [sqlalchemy] query .all and .count return different results when used with a subquery

2012-10-24 Thread dnathe4th
I'm having a problem related to this as well. Is it possible for a join to get tripped up in the de-dup process or is that guaranteed to only occur for the mapper entity I query on? I am getting the de-duping if I query on the mapped entity, but if I query on the id of the entity I get the full