Hi i'm using jsonb_agg for create array of objects. But when i want to create it with multiple json im getting this error.
ERROR: function jsonb_agg(json, json) does not exist
This is what im trying to do
SELECT
station.id AS "objectID",
station.name AS "objectName",
station.activity,
'Station'::text AS unit,
jsonb_agg(
json_build_object('key'::text, 'value'::text),
json_build_object('key'::text, 'value'::text),
...
) AS "childrenList"
FROM eqp_stations station
Is there any way to merge multiple json into array of objects
I hard coded json key and value pairs but I am going to fill these areas later.
Expected Json object like
{
"objectId":123,
"objectName":"blabla",
"unit":"Station",
"childrenList": [
{"key":"value"},
{"key":"value"},
...
]
}
jsonbfunction with arguments returningjsonvalues. You might tryjson(b)_build_objectfunctions as arguments...json_aggcould be replaced withjsonb_build_arrayand that is is, assuming you know the number of children in advance.