[web2py] issue with conditional columns in select with web2py dal query

46 views
Skip to first unread message

Richard

unread,
Oct 21, 2015, 12:02:50 PM10/21/15
to web2py-users
Hello,

I think I just hit a limitation with web2py dal select query build with conditions...

Here the issue:

if someflag:
    columns = [(db[table].date - db.other_table.received_timestamp.date()).avg().with_alias('avg_date')]  # This one does work
    # Failed on : 'Field' object has no attribute 'date'
    columns = [lambda: (db[table].date - db.other_table.received_timestamp.date()).avg().with_alias('avg_date')]  # This one does work neither
    # Failed on : 'function' object has no attribute 'type'
else:
    columns = [(db[table].date - db.other_table.date.date()).avg().with_alias('avg_date')]  # This one works

db(...).select(*columns)

Is there a way to make aggregate lazy somehow?

Thanks a lot

Richard

Richard Vézina

unread,
Oct 21, 2015, 2:28:33 PM10/21/15
to web2py-users
Workaround it like that :

if someflag:
    try:
        base_date = db.other_table.received_timestamp.date()
    except:
        base_date = db.other_table.date
    columns = [(db[table].date - base_date).avg().with_alias('avg_date')]  # Works YEAH!
else:
    columns = [(db[table].date - db.other_table.date.date()).avg().with_alias('avg_date')] 

Richard

--
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 web2py+un...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages