Используйте функцию jsonb_array_elements(example_column),
пример:
with example_table(example_column) as (
values
(jsonb '[1, 2]'),
(jsonb '[3]')
)
select jsonb_agg(value)
from example_table
cross join jsonb_array_elements(example_column)
jsonb_agg
-----------
[1, 2, 3]
(1 row)
Вы можете определить порядок сортировки агрегированных элементов и / или удалить дубликаты, например ::
with example_table(id, example_column) as (
values
(1, jsonb '[1, 2]'),
(2, jsonb '[3]'),
(3, jsonb '[3, 1]')
)
select
jsonb_agg(value order by id) as agg1,
jsonb_agg(value order by value) as agg2,
jsonb_agg(distinct value order by value) as agg3
from example_table
cross join jsonb_array_elements(example_column)
agg1 | agg2 | agg3
-----------------+-----------------+-----------
[1, 2, 3, 3, 1] | [1, 1, 2, 3, 3] | [1, 2, 3]
(1 row)