Skip to content

Instantly share code, notes, and snippets.

@sagarchauhan005
Created April 30, 2020 07:27
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