Let's say I have the following data:
gp_id | p_id
------|-------
1 | 123
2 | 432
2 | 222
For the purposes of business logic I have to transform that into this:
gp_id | p_ids
------|----------
1 | {123}
2 | {432,222}
I tried to do something like this (actually, I understand that this is the wrong approach, but still):
select gp_id, array(
select p_id from cte
) as p_ids
from cte
And, predictably enough, it returns the following:
gp_id | p_ids
------|--------------
1 | {123,432,222}
2 | {123,432,222}
2 | {123,432,222}
Could anyone please help me with this?
And yes, as a matter of fact, I'm using this in a series of common table expressions.