u_cnt = db.auth_user.id.count().with_alias('user_count')
user_count = db(db.auth_user).select(u_cnt, left = ...).first().user_count
or just passing raw SQL as field:
user_count = db(db.auth_user).select('count(id) AS user_count', left =
...).first().user_count
четверг, 20 августа 2020 г. в 22:27:04 UTC+3, Jim S:
> Clemens
>
> Thanks so much, that worked perfect. I guess I was a little concerned
> about the performance, doing the whole select, but then realized that this
> should cut down on result set size, so shouldn't matter that much.
>
> Again, thank you
>
> -Jim
>
>
> On Thursday, August 20, 2020 at 2:14:26 PM UTC-5, Clemens wrote:
>>
>> Hi Jim,
>>
>> I had this issue some time ago and I solved it by the workaround of using
>> len(db(query).select()). The count()-method is a little more performant,
>> but in my case it didn't matter. If you need the rows object of the select
>> for further processing anyway, you can have the len() on the rows object.
>>
>> It's not perfect, but it works :-)
>>
>> Best regards
>> Clemens
>>
>> On Thursday, August 20, 2020 at 8:52:15 PM UTC+2 Jim S wrote:
>>
>>> Hi
>>>
>>> I'm trying to get the count of records to be returned in a query using:
>>>
>>> db(query).count()
>>>
>>> Adding complexity to the situation is that query may sometimes be over
>>> multiple tables with need a left clause added. When selecting records you
>>> do this by passing the left= parameter inside the .select().
>>>
>>> But, you can't pass anything into the .count() method.
>>>
>>> Has anyone found an efficient way to get a .count() when a left join is
>>> in use?
>>>
>>> -Jim
>>>
>>> (cross-posting to py4web as well)
>>>
>>>
--
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
---
You received this message because you are subscribed to the Google Groups
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/web2py/3eaf1e26-c8bf-4c33-bae2-d47402f445fbn%40googlegroups.com.