Skip to content

Instantly share code, notes, and snippets.

@iambibhas
Created June 15, 2014 10:45
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 iambibhas/351f87bbee00e9d30672 to your computer and use it in GitHub Desktop.
Save iambibhas/351f87bbee00e9d30672 to your computer and use it in GitHub Desktop.
Another way of querying geo data from JSON column
explain analyze
SELECT tmp_table.tid,
tmp_table.screen_name,
tmp_table.text
FROM
(SELECT tid,
data->'user'->>'screen_name' AS screen_name,
data->>'text' AS text,
ST_GeomFromText('POINT(' || CAST(data#>>'{geo,coordinates,1}' as varchar) || ' ' || CAST(data#>>'{geo,coordinates,0}' as varchar) || ')', 4326) AS geom
FROM tweet
WHERE data->>'geo' <> '') AS tmp_table
WHERE ST_Distance(
ST_Transform(geom, 26986),
ST_Transform(ST_GeomFromText('POINT(77.620176 13.004616)',4326), 26986)
) < 50000;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment