[sqlalchemy] Re: Aggregation funnctions as mapped column_properties

2009-10-01 Thread Bj
not sure if the example was clear enough. What I'm trying to do is to convert the following select to a mapped- class: select id, usr_id, rating, ( select COUNT(*) from ratings as r where r.id = ratings.id ), ( select AVG(r.rating) from ratings as r where r.id = ratings.id)

[sqlalchemy] Re: Aggregation funnctions as mapped column_properties

2009-10-01 Thread Michael Bayer
Bj wrote: not sure if the example was clear enough. What I'm trying to do is to convert the following select to a mapped- class: select id, usr_id, rating, ( select COUNT(*) from ratings as r where r.id = ratings.id ), ( select AVG(r.rating) from ratings as r where r.id =

[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

[sqlalchemy] Re: Aggregation

2007-08-08 Thread Paul Colomiets
[EMAIL PROTECTED] wrote: hi, i have similar idea/need within dbcook, although on a somewhat higher level: pre cache_results/: (dbcook/SA) add-on for automaticaly-updated database denormalisation caches of intermediate results, each one depending on particular pattern of usage. Wishful

[sqlalchemy] Re: Aggregation

2007-08-08 Thread sdobrev
On Wednesday 08 August 2007 12:18:24 Paul Colomiets wrote: [EMAIL PROTECTED] wrote: hi, i have similar idea/need within dbcook, although on a somewhat higher level: pre cache_results/: (dbcook/SA) add-on for automaticaly-updated database denormalisation caches of intermediate results,

[sqlalchemy] Re: Aggregation

2007-08-07 Thread Paul Colomiets
Michael Bayer wrote: i wonder though if theres some way that could get out of sync with the actual number. you'd have to be careful to establish this update. if you wanted to use a mapper extension to do it, then youd have to issue the UPDATE directly, the change to the comment_count

[sqlalchemy] Re: Aggregation

2007-08-07 Thread Michael Bayer
On Aug 7, 1:20 pm, Paul Colomiets [EMAIL PROTECTED] wrote: 1. func.if_(...) - tries to sql function if_(...), but func._if(...) - _i(...) I believe is typo? er, probably. func is trying to sidestep various _ underscore attributes i think. do you need to say _if(...) ? 2. If there a

[sqlalchemy] Re: Aggregation

2007-08-07 Thread sdobrev
I've finally done first POC implementation of this feature. Basic usage looks like: import aggregator as a mapper(Line, lines, extension=a.Quick(a.Count(blocks.c.lines), a.Max(blocks.c.lastline, lines.c.id))) (You also need foreign keys) hi, i have similar idea/need within

[sqlalchemy] Re: Aggregation

2007-08-07 Thread Paul Colomiets
[EMAIL PROTECTED] wrote:= http://www.mr-pc.kiev.ua/projects/SQLAlchemyAggregation this gives me 404 Sorry: http://www.mr-pc.kiev.ua/en/projects/SQLAlchemyAggregator --~--~-~--~~~---~--~~ You received this message because you are subscribed to

[sqlalchemy] Re: Aggregation

2007-08-07 Thread Paul Colomiets
Michael Bayer wrote: On Aug 7, 1:20 pm, Paul Colomiets [EMAIL PROTECTED] wrote: 1. func.if_(...) - tries to sql function if_(...), but func._if(...) - _i(...) I believe is typo? er, probably. func is trying to sidestep various _ underscore attributes i think. do you need to say

[sqlalchemy] Re: Aggregation

2007-08-03 Thread Paul Colomiets
Michael Bayer wrote: Hmmm, do you mean joining relations against a subrelation that uses an aggregate like MAX ? i'd like to see what you have in mind for this. Well, I think I've not explained it correctly. It looks quite like you're saying, but I want that aggregations to be stored

[sqlalchemy] Re: Aggregation

2007-08-03 Thread Michael Bayer
On Aug 3, 2007, at 10:57 AM, Paul Colomiets wrote: Michael Bayer wrote: Hmmm, do you mean joining relations against a subrelation that uses an aggregate like MAX ? i'd like to see what you have in mind for this. Well, I think I've not explained it correctly. It looks quite like

[sqlalchemy] Re: Aggregation

2007-08-03 Thread Michael Bayer
On Aug 3, 2007, at 5:57 AM, Paul Colomiets wrote: Hi, Is there some aggregation ability built-in in the SQLAlchemy? I want some simple functions like counting rows and determining the last one. I know it's something simple to implement with Mapper Extensions, but may be there are

[sqlalchemy] Re: Aggregation

2007-08-03 Thread Paul Colomiets
Michael Bayer wrote: we've just added the atomic update thing to 0.4 (note the uppercase Article which produces a column expression): article.comment_count = Article.comment_count + 1 session.flush() That's great! It's quite unconvenient here, but has a lot of good use cases. i wonder