On May 30, 2013, at 5:19 PM, Kent <jkentbo...@gmail.com> wrote: > > Solution A: > ================ > Group by all columns (yielding the same effect as "distinct"), but which > makes the window analytical function process after the group by and yields > the correct count (17 instead of 72):
are all those columns indexed? even if they are, crappy query... > > OR Solution B: > ================ > Put the "count(*) over ()" in an outer select, like this: > > select count(*) over () as recordcount, anon.* > from ( > select distinct tablea.colx, tableb.coly > from tablea, tableb > ) as anon > limit 100 this is very much how SQLAlchemy wants you to do it. > > Either solution yields the correct answer I believe, but I'm having > difficulty translating the SQL that I know will work into sqlalchemy land. > > > For Solution B, I don't know how to wrap my query in an outer select (similar > to the LIMIT implementation for Oracle) in a way that will still allow > sqlalchemy to extract rows into instances: from_self() can do this (probably use add_column() for the window function), or subquery() should work very well. subq = q.subquery(); q = query(func.count('*').over().label(..), subq); . send me a quick example if that's not working and I'll work out the query. -- You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To unsubscribe from this group and stop receiving emails from it, send an email to sqlalchemy+unsubscr...@googlegroups.com. To post to this group, send email to sqlalchemy@googlegroups.com. Visit this group at http://groups.google.com/group/sqlalchemy?hl=en. For more options, visit https://groups.google.com/groups/opt_out.