invalid memory alloc request size on simple query with array_agg on Postgres 9.3
In your first query, you do the aggregate on the whole table, then limit the single row result to 200 rows.  This is because the LIMIT is applied on the result set of its containing query.

If you did an EXPLAIN select array_agg(st.search_token) from search_token st limit 200;, it would return something like

Limit [...]
   -&gt; [...]Aggregate [...]


Basically, the closer one node in the plan is to the bottom, the earlier it is executed (this is more complicated than that, but in this context it is true).

The good news is that you found the solution, too :)