In a Postgres 11 database, there's a table (traces) with one column of type JSONB (trace). The JSON value is always a nested array in the form of:
[ ["a", "b"], ... ]
There's at least one sub-element in the array in each row. I want to add a second column (computed, but for now a simple query suffices for this scenario), which contains a string representation of the array column in the form of
a.b c.d.e
from an array value of [["a","b"],["c","d","e"]].
I have tried several things, but I might be missing a bit a theory here. In my mind, this would involve some kind of double-aggregation, once for each nested array, then again for the outermost array. How do I express that in a query (if that is even the right approach)?
My starting point was this query to first get access to all nested arrays:
SELECT nested FROM traces, jsonb_array_elements(trace) nested;
It does return a list of nested arrays, with nested being JSONB I think. I continued with approaches like this:
SELECT
trace,
array_to_string(array_agg(nested), ' ')
FROM traces,
jsonb_array_elements(trace) nested
GROUP BY trace;
But I ran into the issue of not being able to "nest" aggregation functions.