Skip to content

Instantly share code, notes, and snippets.

@Tab3r
Created October 3, 2017 14:13
Show Gist options
  • Save Tab3r/dc15dbdc576e1a7ef0f8a2cf07958e6a to your computer and use it in GitHub Desktop.
Save Tab3r/dc15dbdc576e1a7ef0f8a2cf07958e6a to your computer and use it in GitHub Desktop.
SELECT jsonb_build_object(
'type', 'FeatureCollection',
'features', jsonb_agg(feature)
)
FROM (
SELECT jsonb_build_object(
'type', 'Feature',
'id', gid,
'geometry', ST_AsGeoJSON(geom)::jsonb,
'properties', to_jsonb(row) - 'gid' - 'geom'
) AS feature
FROM (SELECT * FROM input_table) row) features;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment