My table structure is as below.
I want to return the data column but joined together as a JSON where type = 1 and order by the time column. I used STRING_AGG(), but its not what I want since I need to serialize this in the other side.
| id | type |data | time |
| ---|----- | ------------------------------- |-------------------|
| 1 | 1 |[{"X":55,"Y":97}] |2022-03-02 17:20:21|
| 2 | 1 |[{"X":3,"Y":6},{"X":39,"Y":9}] |2022-03-02 17:20:25|
| 3 | 5 |[{"X":9,"Y":9},{"X":33,"Y":1}] |2022-03-02 17:20:29|
Basically I need to return [{"X":55,"Y":97},{"X":3,"Y":6},{"X":39,"Y":9}]
geometrytype? If this is a MULTIPOINT or LINESTRING, you could use UnionAggregate to combine the pointsFOR JSONMULTIPOINTin ageometrycolumn and even add spatial indexes if needed. If you want to keep using JSON, you'll have to parse the content and generate a new JSON string as Zhorov shows