2

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?

Alicia
  • 1,152
  • 1
  • 23
  • 41
arossi
  • 23
  • 4
  • Are you trying to do something like this? ;) - http://stackoverflow.com/questions/39805736/get-join-table-as-array-of-results-with-postgresql-nodejs – vitaly-t Feb 03 '17 at 14:51
  • Not really, thank you; I am using a GET from the browser to get the data to populate a leaflet map. If I edit the Select result (by hand) to remove the non map related key values at the beginning and end of the returned Object, then the map renders exactly right. I just can't figure out how to stop the 'select', 'rowCount', 'OID' data etc from getting into the query result in the first place .... this data is not in the postgres table itself. – arossi Feb 03 '17 at 15:10

0 Answers0