I am using a node-postgres 'client.query' to Select from a postgres 9.6/postgis 2.3 db. The Select statement is:
SELECT json_build_object('type','FeatureCollection','crs',json_build_object ('type','name','properties',json_build_object ('name','EPSG:3857')),'features',json_agg(json_build_object ('type','Feature','id',id,'geometry',ST_AsGeoJSON (geom)::json,'properties',json_build_object('proprietor', proprietor))))
FROM enclosers
The query works fine and returns the data that I require except that the first part of the json object returned is the detail of the query itself. I have shown it below as a json string but it is the same in the json object itself:
{ "command": "SELECT", "rowCount": 1, "oid": null, "rows": [ { "json_build_object": { "type": "FeatureCollection" ....
Likewise the end of the output contains more data about the query itself:
"fields": [ { "name": "json_build_object", "tableID": 0, "columnID": 0, "dataTypeID": 114, "dataTypeSize": -1, "dataTypeModifier": -1, "format": "text" } ], "_parsers": [ null ], "rowAsArray": false }
I cannot find a way to suppress or exclude this data. I have tried different forms of Select using row_to_json etc but they all come back with a similar result. When I execute the query directly in pgadmin, the results are clean and as one would expect.
Has anybody else experienced this issue and know how to deal with it please?