<div dir="ltr">Hi Matthew!<br><br>I the future we can add new function `group_to_list`:<div><br></div><div>    select((p, group_to_list(c)) for p in Person for c in p.cars if c.make in ("Toyota", "Honda"))<br><br>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 `group_concat`.<br><br>Right now in your case it is necessary to perform grouping in Python:<br><br>    import itertools<br>    query = select((p, c) for p in Person for c in p.cars if c.make in ("Toyota", "Honda"))<br>    result = [<br>        (person, [ car for person, car in group ])<br>        for person, group in itertools.groupby(query, key=lambda row: row[0])  # row[0] is person<br>    ]<br><br><br>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<br><br>Regards,<br>Alexander<br><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Jul 1, 2016 at 12:57 AM, Matthew Bell <span dir="ltr"><<a href="mailto:matthewrobertbell@gmail.com" target="_blank">matthewrobertbell@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div><pre><span>Hello, if I have this query (from the docs)<br></span></pre><pre><span><br>select</span><span>((</span><span>p</span><span>,</span> <span>c</span><span>)</span> <span>for</span> <span>p</span> <span>in</span> <span>Person</span> <span>for</span> <span>c</span> <span>in</span> <span>p</span><span>.</span><span>cars</span> <span>if</span> <span>c</span><span>.</span><span>make</span> <span>in</span> <span>(</span><span>"Toyota"</span><span>,</span> <span>"Honda"</span><span>))</span></pre><br></div>How can I have p be distinct, while c is not distinct?<br><br><pre><span>select</span><span>((distinct(</span><span>p)</span><span>,</span> <span>c</span><span>)</span> <span>for</span> <span>p</span> <span>in</span> <span>Person</span> <span>for</span> <span>c</span> <span>in</span> <span>p</span><span>.</span><span>cars</span> <span>if</span> <span>c</span><span>.</span><span>make</span> <span>in</span> <span>(</span><span>"Toyota"</span><span>,</span> <span>"Honda"</span><span>))<br><br></span></pre><pre><span>doesn't seem to work.<br><br></span></pre><pre><span>Thanks!<span class="HOEnZb"><font color="#888888"><br></font></span></span></pre><span class="HOEnZb"><font color="#888888"><br clear="all"><div><br>-- <br><div data-smartmail="gmail_signature">Regards,<br><br>Matthew Bell<br></div>
</div></font></span></div>
<br>_______________________________________________<br>
ponyorm-list mailing list<br>
<a href="mailto:ponyorm-list@ponyorm.org">ponyorm-list@ponyorm.org</a><br>
<a href="/ponyorm-list" rel="noreferrer" target="_blank">/ponyorm-list</a><br>
<br></blockquote></div><br></div>