I'm sorry for the vague title, but I simply don't know the right words to describe this.
I have this query that transforms a bunch of columns into an object that works just fine:
SELECT row_to_json(t)
FROM (
SELECT type, properties, geometry FROM "bgbCargoMinardJSON"
) t
However, I want to group the objects that fall within a certain category into an array. This category is defined by a fourth column inside my table named "cargoProductId". The array should have the value of "cargoProductId" as the key. So:
"961":[
{"type":"Feature",....
{"type":"Feature",....
{"type":"Feature",....
],
"962":[
.....
]
So I've been struggling with this for the last 1 1/2 hours or so. I really have no clue how to do this. This is what I have right now:
SELECT array_agg(row_to_json(t))
FROM (
SELECT type, properties, geometry FROM "bgbCargoMinardJSON"
) t) FROM "bgbCargoMinardJSON" GROUP BY "carProductId"