[sqlalchemy] Re: aggregation with count and webhelpers.paginate

2009-06-22 Thread King Simon-NFHD78
-Original Message- From: sqlalchemy@googlegroups.com [mailto:sqlalch...@googlegroups.com] On Behalf Of Hollister Sent: 20 June 2009 02:15 To: sqlalchemy Subject: [sqlalchemy] Re: aggregation with count and webhelpers.paginate Well, that worked great: q

[sqlalchemy] Re: aggregation with count and webhelpers.paginate

2009-06-22 Thread Bobby Impollonia
...@motorola.com wrote: -Original Message- From: sqlalchemy@googlegroups.com [mailto:sqlalch...@googlegroups.com] On Behalf Of Hollister Sent: 20 June 2009 02:15 To: sqlalchemy Subject: [sqlalchemy] Re: aggregation with count and webhelpers.paginate Well, that worked great:     q

[sqlalchemy] Re: aggregation with count and webhelpers.paginate

2009-06-19 Thread Hollister
Update: If I run: results = meta.Session.execute(s).fetchall() and pass that to paginate, it works. I guess I just needed the ResultProxy, and not a collection of mapped objects. Mike, if you have any additional insight for me, I would appreciate it. On Jun 19, 11:30 am, Hollister

[sqlalchemy] Re: aggregation with count and webhelpers.paginate

2009-06-19 Thread Hollister
The bad news with results = meta.Session.execute(s).fetchall() is that it runs for every page in the paginator, fetching all rows each time. Thoughts, anyone? On Jun 19, 12:17 pm, Hollister a.hollister.willi...@gmail.com wrote: Update: If I run:     results =

[sqlalchemy] Re: aggregation with count and webhelpers.paginate

2009-06-19 Thread Michael Bayer
Hollister wrote: When I run this, I get: Module sqlalchemy.orm.query:1956 in setup_context          context.froms.append(self.selectable)                if context.order_by is False and self.mapper.order_by:                    context.order_by = self.mapper.order_by  if context.order_by

[sqlalchemy] Re: aggregation with count and webhelpers.paginate

2009-06-19 Thread Michael Bayer
oh. if the paginator uses slices to provide LIMIT/OFFSET, you need to construct a Query that can be limited via slice. don't use select() here, use Query fully. Hollister wrote: The bad news with results = meta.Session.execute(s).fetchall() is that it runs for every page in the paginator,

[sqlalchemy] Re: aggregation with count and webhelpers.paginate

2009-06-19 Thread Hollister
Here you go: URL: http://dev:5000/hits/referrers File '/home/aw/venv/dev/lib/python2.6/site-packages/WebError-0.10.1- py2.6.egg/weberror/evalexception.py', line 431 in respond app_iter = self.application(environ, detect_start_response) File

[sqlalchemy] Re: aggregation with count and webhelpers.paginate

2009-06-19 Thread Michael Bayer
you can't call count() when you've used from_statement, that should be raising an error. the bug is that no error is being raised. Hollister wrote: Here you go: URL: http://dev:5000/hits/referrers File '/home/aw/venv/dev/lib/python2.6/site-packages/WebError-0.10.1-

[sqlalchemy] Re: aggregation with count and webhelpers.paginate

2009-06-19 Thread Hollister
Ok, I see. So what's the best way for me to construct and execute this query? On Jun 19, 1:30 pm, Michael Bayer mike...@zzzcomputing.com wrote: you can't call count() when you've used from_statement, that should be raising an error.   the bug is that no error is being raised. Hollister

[sqlalchemy] Re: aggregation with count and webhelpers.paginate

2009-06-19 Thread Michael Bayer
Hollister wrote: Ok, I see. So what's the best way for me to construct and execute this query? use Query: session.query(MyClass.someid, MyClass.somethingelse).filter(..whatever..).order_by(..whatever...) On Jun 19, 1:30 pm, Michael Bayer mike...@zzzcomputing.com wrote: you can't call

[sqlalchemy] Re: aggregation with count and webhelpers.paginate

2009-06-19 Thread Hollister
Well, that worked great: q = meta.Session.query(m.Hit.referer, func.count(m.Hit.id))\ .group_by(m.Hit.referer)\ .order_by(func.count(m.Hit.id).desc()) Thanks! ps: Is there a better way to specify the count in the order_by? On Jun 19, 2:58 pm, Michael Bayer