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
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,
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
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