[sqlalchemy] Re: Using count and distinct with window function

2012-05-16 Thread Eduardo
To put it more clear why: rows = session.query(*[func.count().over().label(count)]+map(lambda column: MyClass.__dict__[columns],columns)).filter(...).limit(n).offset(m).all() works and *rows = session.query(*[func.count().* *over().label(count)]+map(**lambda column:

Re: [sqlalchemy] Re: Using count and distinct with window function

2012-05-16 Thread Michael Bayer
whats the SQL you're looking for ?work it out from a SQL perspective first - get an exact SELECT, then run it straight on that database, to work out what should be done here. Window functions + DISTINCT + LIMIT/OFFSET sounds like it's really getting out there, and I'm not even sure what

[sqlalchemy] Re: Using count and distinct with window function

2012-05-16 Thread Eduardo
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:

[sqlalchemy] Re: Using count and distinct with window function

2012-05-16 Thread Eduardo
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

Re: [sqlalchemy] Re: Using count and distinct with window function

2012-05-16 Thread Eduardo
*SORRY I want to create query that will return as a first element the number of hits * *SELECT COUNT(*) FROM(SELECT (DISTINCT(col1,col2,col3)) FROM mytable where col1='something**' LIMIT 1 OFFSET 2) and in the second part should be values of the hits **SELECT (DISTINCT(col1,col2,col3)) FROM

Re: [sqlalchemy] Re: Using count and distinct with window function

2012-05-16 Thread Michael Bayer
print Session().query( mytable.c.col1, mytable.c.col2, mytable.c.col3).\ distinct().\ filter(mytable.c.col1=='something').\ limit(1).offset(2).\ from_self(func.count('*')) or just say count() instead of from_self(), will

Re: [sqlalchemy] Re: Using count and distinct with window function

2012-05-16 Thread Eduardo
Am Mittwoch, 16. Mai 2012 19:59:10 UTC+2 schrieb Michael Bayer: If I put count() the result will be the number of hits I would like to have both the number of hits and resulting column values for example [(33,val1,val2,val3),(33, val21,val22,val23),...] If I execute it with Session().query(

Re: [sqlalchemy] Re: Using count and distinct with window function

2012-05-16 Thread Michael Bayer
On May 16, 2012, at 2:20 PM, Eduardo wrote: Am Mittwoch, 16. Mai 2012 19:59:10 UTC+2 schrieb Michael Bayer: If I put count() the result will be the number of hits I would like to have both the number of hits and resulting column values for example you'd need to use GROUP BY for that.