[sqlalchemy] Re: How to use distinct on a particular column?

2009-04-01 Thread Michael Bayer
Stu.Axon wrote: I'm having another go at converting some sql to sqlalchemy: select count(distinct build.device_id) from channelbuild join build on build.id = channelbuild.build_id where

[sqlalchemy] Re: How to use distinct on a particular column?

2009-04-01 Thread Stu.Axon
I tried this session\ .query(func.count(distinct(build.device_id)))\ .filter(channelbuild.channel_id == 9)\ .filter(build.in_icp == False)\ .scalar() It generated this sql: SELECT count(DISTINCT backfill_build.device_id) AS count_1 FROM backfill_build,

[sqlalchemy] Re: How to use distinct on a particular column?

2009-04-01 Thread Michael Bayer
Stu.Axon wrote: I tried this session\ .query(func.count(distinct(build.device_id)))\ .filter(channelbuild.channel_id == 9)\ .filter(build.in_icp == False)\ .scalar() It generated this sql: SELECT count(DISTINCT backfill_build.device_id) AS count_1 FROM

[sqlalchemy] Re: How to use distinct on a particular column?

2009-04-01 Thread Stu.Axon
Doh, must be tired. That works cool... finally have my first SQLAlchemy ORM stuff working. Thanks... Is it best practice to move the joins into the filter(where) clause like this, (in this case channelbuild.build_id is FK to the PK build.id)? I tried putting the join inside the distinct