Collect data of many2many in SQL query.
Sometimes in query needed to get all customer/partner data including tags. Here example to get all customer tags data in query.
Example:
select
res_partner.name as "Partner Name",
res_partner.phone as "Phone",
(select STRING_AGG(ctg.name,',') from res_partner_category ctg left join res_partner_res_partner_category_rel ct ON ct.partner_id=res_partner.id where ctg.id=ct.category_id) as "Tags"
from res_partner;