
--
-- Output the result of "SELECT * FROM data_collector;" in GeoJSON format
--
--SELECT row_to_json(fc) FROM (SELECT 'FeatureCollection' AS type, array_to_json(array_agg(f)) AS features FROM (SELECT 'Feature' AS type, ST_AsGeoJSON(lg.dc_geom)::json AS geometry, row_to_json((SELECT l FROM (SELECT cartodb_id, description, name) AS l)) AS properties FROM data_collector AS lg) AS f) AS fc;


--
-- The same SQL statement as above but expressed in multi lines for easy readability
--
SELECT row_to_json(fc) FROM (
	SELECT 'FeatureCollection' AS type, array_to_json(array_agg(f)) AS features FROM (
		SELECT 'Feature' AS type,
			ST_AsGeoJSON(lg.dc_geom)::json AS geometry,
			row_to_json((SELECT l FROM (SELECT cartodb_id, description, name) AS l)) AS properties
		FROM data_collector AS lg
	) AS f
) AS fc;
