Here it is...
db.define_table('TABLE_of_sites',
Field('site_id', 'reference sites'),
Field('title', 'string'),
Field('date','datetime'),
...
Field('updated','datetime', update=request.now, writable=False),
format='%(site_id)s'
)
There are multiple entries for a particular title, so I want to get the
MAX(date) entry.
This is the query I used (result = not working):
table = 'TABLE_of_sites'
max = db[table].date.max()
row = db().select(max)
Other queries on the table work fine, but not aggregates. I tried count(),
max() and they both don't work.
Queries that work are the straightforward ones:
db(db[table]).select()
In fact I also tried distinct and there's an error too, I will make a
separate post.
On Friday, July 14, 2017 at 1:22:01 AM UTC+8, Richard wrote:
>
> @lyn2py, seems more a issue with naming in your model than anything
> else... Can you show us your model?
>
> On Thu, Jul 13, 2017 at 1:16 PM, lyn2py <[email protected] <javascript:>>
> wrote:
>
>> I'm using a simple query to get aggregate:
>>
>> max = db.table.date.max()
>> row = db().select(max)
>>
>> Just following the example here
>> http://www.web2py.com/books/default/chapter/29/06/the-database-abstraction-layer#sum-avg-min-max-and-len
>>
>> But I ran into this error:
>>
>> Traceback (most recent call last):
>> File "/Users/web2py/web2py/gluon/main.py", line 445, in wsgibase
>> serve_controller(request, response, session)
>> File "/Users/web2py/web2py/gluon/main.py", line 180, in serve_controller
>> page = run_controller_in(request.controller, request.function,
>> environment)
>> File "/Users/web2py/web2py/gluon/compileapp.py", line 660, in
>> run_controller_in
>> vars = vars.xml()
>> File "/Users/web2py/web2py/gluon/packages/dal/pydal/objects.py", line
>> 2497, in xml
>> rv = self.db.represent('rows_xml', self)
>> File "/Users/web2py/web2py/gluon/packages/dal/pydal/base.py", line 834,
>> in represent
>> return self.representers[name](*args, **kwargs)
>> File "/Users/web2py/web2py/gluon/sqlhtml.py", line 3319, in __init__
>> tablemap = dict(((f.tablename, f.table) for f in fieldmap.values()))
>> File "/Users/web2py/web2py/gluon/sqlhtml.py", line 3319, in <genexpr>
>> tablemap = dict(((f.tablename, f.table) for f in fieldmap.values()))
>> AttributeError: 'Expression' object has no attribute 'tablename'
>>
>>
>> Kindly assist.
>>
>>
>> On Tuesday, July 11, 2017 at 5:40:08 AM UTC+8, Massimo Di Pierro wrote:
>>>
>>> It took a year. Thanks to everybody who contributed. There are a ton of
>>> bug fixes and speed improvements.
>>>
>>> I would encourage everybody who contributed to add a comment in this
>>> thread explaining the main features/improvements they have made.
>>>
>>> If anything does not work or was broken it is only fault and I will
>>> remedy if reported.
>>>
>>> Massimo
>>>
>> --
>> 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] <javascript:>.
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>
--
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].
For more options, visit https://groups.google.com/d/optout.