Skip to content

Instantly share code, notes, and snippets.

@ashaw
Last active September 14, 2020 21:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ashaw/f8ed7c985720b5f6b052223eff8ca136 to your computer and use it in GitHub Desktop.
Save ashaw/f8ed7c985720b5f6b052223eff8ca136 to your computer and use it in GitHub Desktop.
select jsonb_build_object(
'type', 'FeatureCollection',
'features', jsonb_agg(features.feature)
)
from(
select jsonb_build_object(
'type', 'Feature',
'id', ogc_fid,
'geometry', ST_AsGeoJSON(the_geom)::jsonb,
'properties', to_jsonb(inputs) - 'gid'
) as feature from (
(select YOUR QUERY)
inputs) features
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment