I have created a function in postgres that returns json.
The function is used in an API and returns this:
[
{
"jobfeed_beroepen_list": [
{
"profession_code": 3674,
"profession_descr": "Manusje van alles (boodschappen, post en goederen)"
},
{
"profession_code": 4107,
"profession_descr": "Algemeen medewerker"
}
]
}
]
But I want it to return this:
[
{
"profession_code": 3674,
"profession_descr": "Manusje van alles (boodschappen, post en goederen)"
},
{
"profession_code": 4107,
"profession_descr": "Algemeen medewerker"
}
]
Question: what do I have to change in the code?
--------------- this is the function --------------
CREATE OR REPLACE FUNCTION api.fnc_jobfeed_beroepen(
)
RETURNS TABLE(jobfeed_beroepen_list jsonb)
LANGUAGE 'plpgsql'
COST 100
VOLATILE
ROWS 1000
AS $BODY$
DECLARE
BEGIN
jobfeed_beroepen_list := to_jsonb(array_agg(t)) FROM
(SELECT profession_code, profession_descr
FROM skillcv.jobfeed_beroepen
WHERE use = 1
) AS t;
RETURN QUERY SELECT jobfeed_beroepen_list;
END;
$BODY$;