title: How to aggregate two PostgreSQL columns to an array separated by brackets
body: <p>I would like to concatenate two columns using a group-by query resulting in an array separed with brackets. I know this question is related to <a href="https://stackoverflow.com/questions/43870/how-to-concatenate-strings-of-a-string-field-in-a-postgresql-group-by-query">this</a> question, but as usual my use-case is a little different.</p>
  
  <p>A simple example (also as <a href="http://sqlfiddle.com/#!15/e6ce0/28" rel="noreferrer"><strong>SQL Fiddle</strong></a>).
  Currently my query returns the following:</p>
  
  <pre><code>ID  X   Y
  3   0.5 2.71
  3   1.0 2.50
  3   1.5 2.33
  6   0.5 2.73
  6   1.5 2.77
  </code></pre>
  
  <p>But where I would like concatenate/aggregate the <code>X</code>/<code>Y</code> columns to get the following:</p>
  
  <pre><code>ID  XY
  3   [[0.5,2.71],[1.0,2.50],[1.5,2.33]]
  6   [[0.5,2.73],[1.5,2.77]]
  </code></pre>
  
  <p>Currently I've tried to concatenate the columns into one as follows:</p>
  
  <pre><code>SELECT "ID",concat_ws(', ',"X", "Y") as XY FROM Table1;
  </code></pre>
  
  <p>Which returns:</p>
  
  <pre><code>ID  xy
  3   0.5, 2.71
  3   1, 2.50
  3   1.5, 2.33
  6   0.5, 2.73
  </code></pre>
  
  <p>And used <code>array_agg()</code>:</p>
  
  <pre><code>SELECT "ID",array_to_string(array_agg("X"),',') AS XY
  FROM Table1
  GROUP BY "ID";
  </code></pre>
  
  <p>Resulting in:</p>
  
  <pre><code>ID  xy
  3   0.5,1,1.5
  6   0.5
  </code></pre>
  
  <p>I feel I'm getting closer, but a helping hand would be really appreciated.</p>