[sqlalchemy] Using count and distinct with window function

2012-05-16 Thread Eduardo


Hello,
I have got a query of the following type:

rows = session.query(*[func.count().over().label(count)]+map(lambda column: 
MyClass.__dict__[columns],columns)).filter(...).limit(n).offset(m).all()

it returns the number of results together with values of selected columns. The 
problem is when I try to apply the distinct query I see that 
func.count().over().label(count) does not return correct results, that is, it 
returns the number of results for the query by which the distinct function is 
omitted.
Is there any workaround for this problem?
The query contains no joins.
Thank you
ED

-- 
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/sqlalchemy/-/s2PjnmdvWuwJ.
To post to this group, send email to sqlalchemy@googlegroups.com.
To unsubscribe from this group, send email to 
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.



[sqlalchemy] Using count with distinct?

2009-02-02 Thread Stuart Axon

I've got a fairly simple query in postgres... any idea how I do this in 
sqlalchemy - I couldn't find any info about this

select
count(distinct device_id)
from
externalbuild
join
build
on
build.id = externalbuild.build_id
where
external_id = '1'
and not
is_known


BTW, the recent work looks good - might even help me convert my other queries 
from sql... I thought this one
was the simplest, but failed here too :-\



  

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To post to this group, send email to sqlalchemy@googlegroups.com
To unsubscribe from this group, send email to 
sqlalchemy+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---