Skip to content
Advertisement

How to flat a subarray in Postgres?

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

Output: -[ RECORD 1 ]-------- array | {{1,2},{2,3}}

How do I flat the array, so I can then unnest?

Expected {1, 2, 2, 3}

Advertisement

Answer

unnest() completely flattens the array. If you need the flattened array, then unnest() and follow with an array_agg()

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement