baxx
baxx

Reputation: 4755

Flatten an array of arrays in postgres to a single array

Given something such as the following:

select array[array[1, 2], array[3, 4]]

Which returns

{{1,2},{3,4}}

I would like to know how to flatten this to a single array as:

{1,2,3,4}

Upvotes: 3

Views: 1790

Answers (1)

user3738870
user3738870

Reputation: 1632

This is one way to achieve it:

select array(select unnest(array[array[1, 2], array[3, 4]]));

Result:

{1,2,3,4}

Upvotes: 2

Related Questions