Sample Header Ad - 728x90

Select columns inside json_agg

60 votes
7 answers
178333 views
I have a query like: SELECT a.id, a.name, json_agg(b.*) as "item" FROM a JOIN b ON b.item_id = a.id GROUP BY a.id, a.name; How can I select the columns in b so I don't have b.item_id in the JSON object? I have read about ROW , but it returns a JSON object like: {"f1": "Foo", "f2": "Bar"} I would need to remap the JSON object once it is fetched to match the proper column keys. I'd like to avoid that and keep original column names.
Asked by Yanick Rochon (1651 rep)
Jul 3, 2014, 02:55 PM
Last activity: Feb 7, 2024, 10:49 PM