How to merge multiple arrays in one?

Here’s one way to do it:

create table t(id int, j json);

insert t values
  (1 , '["label_1", "label_2"]'), 
  (2 , '["label_3", "label_4"]');

with r as (
  select id, x.table_col as c from t join table(json_to_array(j)) as x
)
select json_agg(c) from r;

Result:

+-------------------------------------------+
| json_agg(c)                               |
+-------------------------------------------+
| ["label_1","label_2","label_3","label_4"] |
+-------------------------------------------+
2 Likes