title: Aggregate with a limit in postgres
body: <p>In this query, each row of table <code>a</code> could have hundreds of rows of table <code>b</code> associated with it. So the <code>array_agg</code> contains all of those values. I'd like to be able to set a limit for it, but instide <code>array_agg</code> I can do <code>order by</code> but there's no way to set a limit.</p>
  
  <pre><code>select a.column1, array_agg(b.column2)
  from a left join b using (id)
  where a.column3 = 'value'
  group by a.column1
  </code></pre>
  
  <p>I could use the "slice" syntax on the array but that's quite expensive since it first has to retrieve all the rows then discard the other ones. What's the proper efficient way to do this?</p>