Querying pivot table to return a list of referred rows

I have these 6 tables and query which returns everything I want, but I want to add a new pivot table, so I can get a list of rows linked to it.

Query:

SELECT DISTINCT ON (pg.id, p.prod_id)
    pg.group_name, p.name AS prod_name, v.version,
COALESCE((select default_something from version_child where version_id = v.id),
(select default_something from product_child where prod_id = p.prod_id),
(select default_something from product_group_child where group_id = pg.id)
) as something
FROM product_group pg
LEFT JOIN product p ON pg.id = p.group_id
LEFT JOIN version v ON v.prod_id = p.prod_id
ORDER BY pg.id, p.prod_id, v.version DESC;

Product Group Table

id  group_name
---------------------------
1   Nice
2   Very Nice

Product table

prod_id  name      group_id
---------------------------
1       something     2
2       psp3          1
3       bundle1       2
4       bundle2       1

Version Table

version_id  prod_id    version
---------------------------
1           2           1.0
2           2           1.1
3           3           2.3
4           1           0.1
5           4           0.4
6           1           0.2

Product Group Child Table

pgt_child_id  group_id    default_something
---------------------------------
1             2            root2
2             1            root1      

Product Child table

pt_child_id  prod_id      default_something
-------------------------------------------
1             2            override2

Version Child Table

v_child_id  version_id    default_something
-------------------------------------------
1             3           winner

New Pivot Table

p_id.    version_id        prod_id
----------------------------------
1          3              2 
2          3              1 
3          5              1

Running the query DBFiddle I get this now:

Group_name  prod_name    version    default_something
-----------------------------------------------------
Nice        psp3          1.1       override2
Nice        bundle2       0.4       root1
Very Nice   something     0.2.      root2
Very Nice   bundle1       2.3.      winner

What I want is like this

Group_name  prod_name    version    default_something  ref
-----------------------------------------------------------
Nice        psp3          1.1       override2           []
Nice        bundle2       0.4       root1               ["something"]
Very Nice   something     0.2.      root2               []
Very Nice   bundle1       2.3.      winner              ["something", "psp3"]

the ref column can be an array or comma separated string. Basically I need to add new column ref which joins pivot table with product and version table and return an array/comma separated string. Would be really helpful to have a modified dbfiddle to do what I want it to it.

How many English words
do you know?
Test your English vocabulary size, and measure
how many words do you know
Online Test
Powered by Examplum