I have a table with all the ids in an array like format and another table that matches the ids with the names. I'm required to write a query that creates creates a new table with 2 columns : ids (which is an array of ids) and names (an array with the corresponding names of the ids).
INPUT TABLES :
main
ids
---------
i1 | i2
i2 | i3
i3
agents
ids names
--------------
i1 agent1
i2 agent2
i3 agent3
OUTPUT :
ids names
----------------------------
(i1, i2) (agent1, agent2)
(i2, i3) (agent2, agent3)
(i3) (agent3)
Output can also be in this format : i1 | i2 for all the elements, that would be fine as well, not absolutely necessary that they should be converted to arrays as I've done below.
I managed to convert the | separated ids column to arrays, but couldn't progress after that.
string_to_array(substr(translate(translate(
main.ids, '|', ','), ' ', ''), 1, length(main.ids) - 3), ',')
AS ids