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);

```
to **merge** arrays you can use `||` operator [more](https://www.postgresql.org/docs/9.6/functions-array.html#:%7E:text=%7C%7C-,array%2Dto%2Darray%20concatenation,-ARRAY%5B1%2C2%2C3%5D%20%7C%7C%20ARRAY%5B4%2C5%2C6)

to put result in **flat list** use `uunest` [func](https://www.postgresql.org/docs/9.6/functions-array.html#:%7E:text=unnest(anyarray%2C%20anyarray%20%5B%2C%20...%5D))

[example:](https://www.db-fiddle.com/f/x5CDdMjLQJ4a4UhANEGG8V/0)

```
select unnest(ARRAY[1,2] || ARRAY[3,2] || ARRAY[4,5]) as number;

```

[![result](https://i.stack.imgur.com/tp30f.png)](https://i.stack.imgur.com/tp30f.png)