Hi,
I am trying to write this SQL coomand:

SELECT DISTINCT(col1, col2,col3) FROM mytable WHERE col1='something' 

in sqlalchemy form:

columns=['col1','col2','col3']

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

this query works it returns the results together with the number of hits.
The problem is that when I apply the distinct() command
*rows = session.query(*[func.count().over().label("count")]+map(lambda column: 
MyClass.__dict__[columns],columns))*.filter(...).limit(n).offset(m).*distict()*.all()
 *func.count().over().label("count") does not show the correct number of hits 
because func.count() relates to all column in table and to those selected - 
that is col1, col2 and col3
My question is how to write the count function that will correctly count number 
of distinct hits but only for the selected columns.*
I tried with:
 
*func.count().over(partition_by=MyClass.col1,MyClass.col2,MyClass.col3).label("count")*

*and it did not work

If I want to use:*

 
*func.count(distinct(MyClass.col1,MyClass.col2,MyClass.col3)).over().label("count")

only one column is allowed as the input argument for the count() function.


Is there any way to solve this?
Thanks* 



Am Mittwoch, 16. Mai 2012 12:07:26 UTC+2 schrieb 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/-/11I7cmn-UaoJ.
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.

Reply via email to