I have a games table with players row. The players column is a jsonb in the form of:
{"digit": [id, id, id, ...], ...}:
select id, players from games;
id | players
-----+-----------------------------
236 | {"10": [27, 23, 25]}
238 | {"7": [22]}
239 | {"1": [], "2": [], "3": []}
237 | {"1": []}
I would like, for each game id (row) have an array of ids, something like this:
id just_arrays
-----+-----------------------------
236 | [27, 23, 25]
238 | [22]
239 | []
237 | []
I would then like to build a document where ids will be changed to player's names (which I have in user table):
id document
-----+-----------------------------
236 | Player Name1 Player Name2 Player Name3
238 | Player Name4
239 |
237 |
How I can achieve that? I've tried something with jsonb_each() but without luck.
{"10": [27, 23, 25]}what is the significance of"10". whether it is fixed or any logic is there