例tags
テーブル:
create table tags(id int primary key, name text, description text);
insert into tags values
(4, 'tag_name_4', 'tag_description_4'),
(5, 'tag_name_5', 'tag_description_5');
あなたがテーブルtags
と最後のテーブルの集計列を結合するためにその要素を使用して、列tags
をネスト解除する必要があります。あなたは配列に配列を集約することができます
select t.id, t.name, array_agg(array[g.name, g.description])
from my_table as t
cross join unnest(tags) as tag
join tags g on g.id = tag
group by t.id;
id | name | array_agg
----+------+-----------------------------------------------------------------
1 | xyz | {{tag_name_4,tag_description_4},{tag_name_5,tag_description_5}}
(1 row)
または文字列を配列に:
select t.id, t.name, array_agg(concat_ws(', ', g.name, g.description))
...
または多分文字列を文字列内:
select t.id, t.name, string_agg(concat_ws(', ', g.name, g.description), '; ')
...