count and distinct

2 views
Skip to first unread message

vkuznet

unread,
Apr 13, 2007, 1:34:55 PM4/13/07
to sqlalchemy
Hi,
I found that if I do
select([func.count(table.c.column)],distinct=True).execute()

the resulting query is
select distinct count(column) from table

but it's not what I wanted. If my column has duplicates you got
counting them, rather then count unique names. The proper SQL query
would be

select count(distinct column) from table

How I can make it with SQLAlchemy syntax?

Thanks,
Valentin.

Michael Bayer

unread,
Apr 13, 2007, 2:24:59 PM4/13/07
to sqlal...@googlegroups.com
you know i was going to say "hey we should add a distinct() function"
but then i checked and its already there:

select([func.count(table.c.column.distinct())]).execute()

this method is actually on _CompareMixin and I should look into
getting it into the generated docs somehow. also i think a
standalone distinct() would be helpful.

Reply all
Reply to author
Forward
0 new messages