[sqlalchemy] expression inside mysql Interval statement

2009-06-19 Thread Alex K
Hi All, I need to construct the following query: select ADDDATE(start,INTERVAL rt_daily_days DAY) from _event where repeat_type = 1; and I have difficulties in dealing with the following statement: INTERVAL rt_daily_days DAY, how can I do this using sqlalchemy func interfaces?

[sqlalchemy] Selecting an ORM from self JOINs and/or from a query with subqueries

2009-06-19 Thread Alexander Kotelnikov
Assuming I have a table CREATE TABLE seq (i int auto_increment primary key, used bool default false); And want to query an mapped object from it which corresponds a query SELECT i,used FROM seq WHERE NOT used AND i+1 IN (SELECT i FROM seq WHERE AND used) or (more or less equivalent) SELECT

[sqlalchemy] Re: Optimizing joined entity loads

2009-06-19 Thread millerdev
Thanks a lot for the tips on how to approach this problem. That's exactly what I needed. in 0.4 you'd get it off the impl (0.5 too, this is just uglier API): Excellent! Here's what I came up with as an initial solution: def poly_load(parent, collection, path): def itersiblings(parent,

[sqlalchemy] Re: Selecting an ORM from self JOINs and/or from a query with subqueries

2009-06-19 Thread Michael Bayer
Alexander Kotelnikov wrote: Assuming I have a table CREATE TABLE seq (i int auto_increment primary key, used bool default false); And want to query an mapped object from it which corresponds a query SELECT i,used FROM seq WHERE NOT used AND i+1 IN (SELECT i FROM seq WHERE AND used) or

[sqlalchemy] Re: Optimizing joined entity loads

2009-06-19 Thread Michael Bayer
millerdev wrote: Thanks a lot for the tips on how to approach this problem. That's exactly what I needed. in 0.4 you'd get it off the impl (0.5 too, this is just uglier API): Excellent! Here's what I came up with as an initial solution: def poly_load(parent, collection, path): def

[sqlalchemy] aggregation with count and webhelpers.paginate

2009-06-19 Thread Hollister
I have a simple query with a group_by and count(), and I'd like to pass this to webhelpers.paginate for display: def referrers(self): s = select([m.hit_table.c.id, m.hit_table.c.referer, func.count (m.Hit.referer).label('count')], from_obj = [m.hit_table],

[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: Selecting an ORM from self JOINs and/or from a query with subqueries

2009-06-19 Thread sacha
Michael, do you mean, that subqueries could not be wrapped into sqlalchemy? what should be the arguments to join() I failed to figure out? how do I reference different instances of seq in fileter() after? Thanks, A On Jun 19, 7:43 am, Michael Bayer mike...@zzzcomputing.com wrote: you can map

[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: Selecting an ORM from self JOINs and/or from a query with subqueries

2009-06-19 Thread Michael Bayer
sacha wrote: Michael, do you mean, that subqueries could not be wrapped into sqlalchemy? you talked about mapping to a select statement. mapping means this: m = mapper(MyClass, someselectable) mapping like the above is usually done against individual tables, and usually once per class per

[sqlalchemy] Re: Selecting an ORM from self JOINs and/or from a query with subqueries

2009-06-19 Thread sacha
I really want to get a clear vision. So, I have a table x and mapped class X. I can use query(X) for simple queries, can I query(X) for structured ones like SELECT * FROM x WHERE x.a IN (SELECT ) ? Same about multi-cartesian product can I use query(X).join() for SELECT * FROM x JOIN x

[sqlalchemy] Re: Selecting an ORM from self JOINs and/or from a query with subqueries

2009-06-19 Thread sacha
I meant SELECT x.* FROM x JOIN x AS x1 JOIN x AS x2 ... WHERE On Jun 19, 1:55 pm, sacha sa...@myxomop.com wrote: Same about multi-cartesian product can I use query(X).join() for SELECT * FROM x JOIN x JOIN x . ? --~--~-~--~~~---~--~~ You received

[sqlalchemy] Re: Selecting an ORM from self JOINs and/or from a query with subqueries

2009-06-19 Thread Michael Bayer
sacha wrote: I really want to get a clear vision. So, I have a table x and mapped class X. I can use query(X) for simple queries, can I query(X) for structured ones like SELECT * FROM x WHERE x.a IN (SELECT ) sel = session.query(X.a).filter(X.b=='foo')

[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