[PonyORM-list] Distinct result?
alexander.kozlovsky at gmail.com
Fri Jul 1 10:29:58 UTC 2016
I the future we can add new function `group_to_list`:
select((p, group_to_list(c)) for p in Person for c in p.cars if c.make
in ("Toyota", "Honda"))
This function will perform aggregation in SQL. In PostgreSQL it will be
translated to `array_agg`, in Oracle to `collect`, in MySQL and SQLite to
Right now in your case it is necessary to perform grouping in Python:
query = select((p, c) for p in Person for c in p.cars if c.make in
result = [
(person, [ car for person, car in group ])
for person, group in itertools.groupby(query, key=lambda row:
row) # row is person
P.S.: By the way, did you try to use db_session(strict=True)? I'm curious
to know if it reduced the memory usage in your application
On Fri, Jul 1, 2016 at 12:57 AM, Matthew Bell <matthewrobertbell at gmail.com>
> Hello, if I have this query (from the docs)
> select((p, c) for p in Person for c in p.cars if c.make in ("Toyota", "Honda"))
> How can I have p be distinct, while c is not distinct?
> select((distinct(p), c) for p in Person for c in p.cars if c.make in ("Toyota", "Honda"))
> doesn't seem to work.
> Matthew Bell
> ponyorm-list mailing list
> ponyorm-list at ponyorm.com
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the ponyorm-list