seems to me that you should use windowing functions instead....
there's no need to introduce a new method.... you can use expression
themselves in the select, and extract the field as usual
myexpr = 'first_value(b_field) over (partition by a_field order by b_field)'
rows = db2(db2.test_table.id > 0).select(myexpr, db2.test_table.a_field)
for row in rows:
print row.aa, row[myexpr]
On Monday, April 28, 2014 4:46:43 PM UTC+2, Manuele wrote:
>
> Il 28/04/14 16:05, Carlos Costa ha scritto:
> > I think he is looking for the first record of each group, not the
> > first record of the entire result.
> > I think there is no such function in web2py yet.
> >
> > I have performed a similar task for reporting using this:
> > https://docs.python.org/2/library/itertools.html#itertools.groupby
> >
> > It will require more computation and memory as you will have do it in
> > memory but is possible and simple.
> starting from the point I'm using postgresql (v. 9.3) I was thinking
> about introducing a new method to the class Expression in dal defined as
> follows:
>
> def array_agg(self):
> db = self.db
> return Expression(db, db._adapter.AGGREGATE, self, 'array_agg',
> self.type)
>
> and get the first argument of the returned list.
>
> maybe this method can be introduced in the dal code but for the moment
> Is there a way to locally "monkey patch" the Expression class for my
> application?
>
> thank you
> Cheers
>
> Manuele
>
--
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.