Skip to content

Instantly share code, notes, and snippets.

@sagarchauhan005
Created April 30, 2020 07:27
Show Gist options
  • Save sagarchauhan005/47e5a4e7c2869344840ac09cc69fa1d2 to your computer and use it in GitHub Desktop.
Save sagarchauhan005/47e5a4e7c2869344840ac09cc69fa1d2 to your computer and use it in GitHub Desktop.
select * from <table> where
ST_CONTAINS(
ST_GEOMFROMTEXT(
CONCAT(
'POLYGON((
', json_unquote(json_extract(column_name, '$.rectangle.bounds."north-east".lng')), '
', json_unquote(json_extract(column_name, '$.rectangle.bounds."north-east".lat')), ',
', json_unquote(json_extract(column_name, '$.rectangle.bounds."north-west".lng')), '
', json_unquote(json_extract(column_name, '$.rectangle.bounds."north-west".lat')), ',
', json_unquote(json_extract(column_name, '$.rectangle.bounds."south-west".lng')), '
', json_unquote(json_extract(column_name, '$.rectangle.bounds."south-west".lat')), ',
', json_unquote(json_extract(column_name, '$.rectangle.bounds."south-east".lng')), '
', json_unquote(json_extract(column_name, '$.rectangle.bounds."south-east".lat')), ',
', json_unquote(json_extract(column_name, '$.rectangle.bounds."north-east".lng')), '
', json_unquote(json_extract(column_name, '$.rectangle.bounds."north-east".lat')), '
))'
)
), POINT('.$long.', '.$lat.'));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment