Question: I have a column which is of type integer array. How can I merge all of them into a single integer array?

For example: If I execute query: 

```
select column_name from table_name

```

I get result set as:

```
-[RECORD 1]----------
column_name | {1,2,3}
-[RECORD 2]----------
column_name | {4,5}

```

How can I get `{1,2,3,4,5}` as final result?

Answer: 
You could use [`unnest`](http://www.postgresql.org/docs/current/interactive/functions-array.html#ARRAY-FUNCTIONS-TABLE) to open up the arrays and then [`array_agg`](http://www.postgresql.org/docs/current/interactive/functions-aggregate.html#FUNCTIONS-AGGREGATE-TABLE) to put them back together:

```
select array_agg(c)
from (
  select unnest(column_name)
  from table_name
) as dt(c);

```
You could use `lateral subquery` for that:

```
select array_agg(u.a)
from (values (array[1, 2, 3]), (array[4, 5])) t (a)
    join lateral unnest(t.a) u (a) on true;

```