[sqlalchemy] Re: problem with join, count on 0.5.0rc3
The new behavior is exactly what I expect, namely that query.count() returns the same as len(query.all()). Are there cases in which this does not make sense or where this would not work? -- Christoph --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalchemy@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~--~~~~--~~--~--~---
[sqlalchemy] Re: problem with join, count on 0.5.0rc3
it should be fine. On Nov 10, 2008, at 6:34 AM, Cito wrote: The new behavior is exactly what I expect, namely that query.count() returns the same as len(query.all()). Are there cases in which this does not make sense or where this would not work? -- Christoph --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalchemy@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~--~~~~--~~--~--~---
[sqlalchemy] Re: problem with join, count on 0.5.0rc3
On 8 Nov., 22:03, Michael Bayer [EMAIL PROTECTED] wrote: oh sorry, also count() is meant to count instances of a single kind of object. So in fact you should be saying: session.query(UserRss).join(Rss, item).count() This question is actually coming from the TurboGears group. The problem here is that our pagination mechanism takes an existing query and checks its result size with count(). I.e. we have no influence on the actual query, we just assume that if you can get all() or slices from the query that you can also count() its results. This had worked all the time up to 0.4.8, but with 0.5 it doesn't work any more. In this example Greg probably wanted to display data from both UserRss *and* Rss in a data grid, so it would not help him to alter the query that way. -- Christoph --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalchemy@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~--~~~~--~~--~--~---
[sqlalchemy] Re: problem with join, count on 0.5.0rc3
On Nov 9, 2008, at 4:46 AM, Cito wrote: On 8 Nov., 22:03, Michael Bayer [EMAIL PROTECTED] wrote: oh sorry, also count() is meant to count instances of a single kind of object. So in fact you should be saying: session.query(UserRss).join(Rss, item).count() This question is actually coming from the TurboGears group. The problem here is that our pagination mechanism takes an existing query and checks its result size with count(). I.e. we have no influence on the actual query, we just assume that if you can get all() or slices from the query that you can also count() its results. This had worked all the time up to 0.4.8, but with 0.5 it doesn't work any more. Assuming your joins are many-to-ones, you can get a straight row count using query(*anything).value(func.count('*')), optionally adding distinct() before you call value(). This is a better strategy than using count() in any case since Query.count() still has a behavioral contract I'm not totally happy with, and you'll get better control over what it is you actually want to count. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalchemy@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~--~~~~--~~--~--~---
[sqlalchemy] Re: problem with join, count on 0.5.0rc3
On Nov 9, 2008, at 9:39 AM, Michael Bayer wrote: On Nov 9, 2008, at 4:46 AM, Cito wrote: On 8 Nov., 22:03, Michael Bayer [EMAIL PROTECTED] wrote: oh sorry, also count() is meant to count instances of a single kind of object. So in fact you should be saying: session.query(UserRss).join(Rss, item).count() This question is actually coming from the TurboGears group. The problem here is that our pagination mechanism takes an existing query and checks its result size with count(). I.e. we have no influence on the actual query, we just assume that if you can get all() or slices from the query that you can also count() its results. This had worked all the time up to 0.4.8, but with 0.5 it doesn't work any more. in the latest trunk r5269 I have overhauled query.count() to properly support multiple entity and column-oriented ORM queries. Your use case will now pass, but be aware that it now takes into account the full list of entities queried. In 0.4, this behavior was broken as it would only use the first entity, and silently ignore the rest. This means that a query such as query(A, B).count() with no JOIN or joining criterion will return the count of the cartesian product of A*B. A query such as query(func.count(A.somecol)).count() will return a value of one, since an aggregate function returns one row. None of this is supported at all in 0.4 and was previously not supported in 0.5. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalchemy@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~--~~~~--~~--~--~---
[sqlalchemy] Re: problem with join, count on 0.5.0rc3
it doesn't know which class on the left side you'd like to join from. so its looking for: sess.query(A, B, C).join((B, A.bs), (C, B.cs)) alternatively, instead of A.bs etc. you can spell out the join condition such as A.b_id==B.id in each tuple. On Nov 8, 2008, at 3:03 PM, Greg wrote: This following request works fine and produce the result I was expecting session.query(UserRss, Rss, Item).join([Rss, Item]). But count doesn't work. Is it a bug, or did I miss something ? str(session.query(UserRss, Rss, Item).join([Rss, Item]).count()) Traceback (most recent call last): File console, line 1, in module File /opt/local/lib/python2.5/site-packages/SQLAlchemy-0.5.0rc3- py2.5.egg/sqlalchemy/orm/query.py, line 1251, in count return self._col_aggregate(sql.literal_column('1'), sql.func.count, nested_cols=list(self._only_mapper_zero().primary_key)) File /opt/local/lib/python2.5/site-packages/SQLAlchemy-0.5.0rc3- py2.5.egg/sqlalchemy/orm/query.py, line 241, in _only_mapper_zero raise sa_exc.InvalidRequestError(This operation requires a Query against a single mapper.) InvalidRequestError: This operation requires a Query against a single mapper. Thanks. Greg --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalchemy@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~--~~~~--~~--~--~---
[sqlalchemy] Re: problem with join, count on 0.5.0rc3
oh sorry, also count() is meant to count instances of a single kind of object. So in fact you should be saying: session.query(UserRss).join(Rss, item).count() On Nov 8, 2008, at 3:03 PM, Greg wrote: This following request works fine and produce the result I was expecting session.query(UserRss, Rss, Item).join([Rss, Item]). But count doesn't work. Is it a bug, or did I miss something ? str(session.query(UserRss, Rss, Item).join([Rss, Item]).count()) Traceback (most recent call last): File console, line 1, in module File /opt/local/lib/python2.5/site-packages/SQLAlchemy-0.5.0rc3- py2.5.egg/sqlalchemy/orm/query.py, line 1251, in count return self._col_aggregate(sql.literal_column('1'), sql.func.count, nested_cols=list(self._only_mapper_zero().primary_key)) File /opt/local/lib/python2.5/site-packages/SQLAlchemy-0.5.0rc3- py2.5.egg/sqlalchemy/orm/query.py, line 241, in _only_mapper_zero raise sa_exc.InvalidRequestError(This operation requires a Query against a single mapper.) InvalidRequestError: This operation requires a Query against a single mapper. Thanks. Greg --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalchemy@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~--~~~~--~~--~--~---
[sqlalchemy] Re: problem with join, count on 0.5.0rc3
here's the new error message in the latest trunk: InvalidRequestError: Can't issue count() for multiple types of objects or columns. Construct the Query against a single element as the thing to be counted, or for an actual row count use Query(func.count(somecolumn)) or query.values(func.count(somecolumn)) instead. On Nov 8, 2008, at 4:03 PM, Michael Bayer wrote: oh sorry, also count() is meant to count instances of a single kind of object. So in fact you should be saying: session.query(UserRss).join(Rss, item).count() On Nov 8, 2008, at 3:03 PM, Greg wrote: This following request works fine and produce the result I was expecting session.query(UserRss, Rss, Item).join([Rss, Item]). But count doesn't work. Is it a bug, or did I miss something ? str(session.query(UserRss, Rss, Item).join([Rss, Item]).count()) Traceback (most recent call last): File console, line 1, in module File /opt/local/lib/python2.5/site-packages/SQLAlchemy-0.5.0rc3- py2.5.egg/sqlalchemy/orm/query.py, line 1251, in count return self._col_aggregate(sql.literal_column('1'), sql.func.count, nested_cols=list(self._only_mapper_zero().primary_key)) File /opt/local/lib/python2.5/site-packages/SQLAlchemy-0.5.0rc3- py2.5.egg/sqlalchemy/orm/query.py, line 241, in _only_mapper_zero raise sa_exc.InvalidRequestError(This operation requires a Query against a single mapper.) InvalidRequestError: This operation requires a Query against a single mapper. Thanks. Greg --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalchemy@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~--~~~~--~~--~--~---