I want to get the JSON response from the function response and I'm able to achieve that. But the problem is on every response I'm getting the function name also how to fix this issue?
Current response
[
{
"__find_attractions_return_json": {
"name": "Conrad Pond",
"lat": 41.01696,
"lon": -74.22462
}
},
{
"__find_attractions_return_json": {
"name": "Crossway Creek",
"lat": 40.46122,
"lon": -74.26292
}
},
.....
.....
]
Required result
[
{
"name": "Conrad Pond",
"lat": 41.01696,
"lon": -74.22462
},
{
"name": "Crossway Creek",
"lat": 40.46122,
"lon": -74.26292
},
.....
.....
]
POSTGRES function
CREATE OR REPLACE FUNCTION public.__find_attractions_return_json(point character varying, cty varchar)
RETURNS SETOF json
LANGUAGE 'plpgsql'
COST 100
VOLATILE
ROWS 1000
AS $BODY$
BEGIN
RETURN QUERY
SELECT
json_build_object(
'name', name,
'lat', lat,
'lon', lon
)
FROM places
WHERE country=cty
AND ST_DWithin(geom::geography,ST_GeogFromText(point), 50000, false);
END
$BODY$;
I'm calling this function from NodeJs.
Any kind of help will much be appreciated.