I have JSONB casted column in table that I'd like to represent as a comma separated list in a single column. I've tried a million different approaches and am coming up short. I can't find anything in the Postgres docs that addresses this particular situation, so hoping for some help!
The table in question looks a little like this:
date | order_id | sales_reps
2019-12-01 | 1234 | [{"id": 100, "user": "Jane Doe"}, {"id": 101, "user": "John Doe"}]
I'd like to render it as:
date | order_id | sales_reps
2019-12-01 | 1234 | Jane Doe, John Doe
I'm able to get relatively close with:
select
date,
order_id,
(select jsonb_agg(t -> 'user') from jsonb_array_elements(sales_reps::jsonb) as x(t)) as sales_reps
from table
date | order_id | sales_reps
2019-12-01 | 1234 | ["Jane Doe", "John Doe"]
But for the life of me I can't seem to get the output I want - have tried a ton of aggregators and jsonb functions to no avail.