I have a table setup with the following columns, and it contains about 100K listing of data.
Column: address | Type: Text
Column: geo_point | Type: geometry(Point,4326)
My question is for each listing, how do I write the radius search query to find all the listing within 5 miles?
Best Answer
Best use
ST_DWithin()
in aLATERAL
join:1.609344
being the factor for converting miles to kilometers. Source: Wikipedia. Assuming meter as unit! The documentation:I think your SRID 4326 uses degrees, not meters. Instructions in this related answer:
You need an index on
geo_point
to make this fast (used byST_DWithin()
automatically):A GiST index can also be used to identify nearest neighbors (in combination with a maximum number -
LIMIT
).Related: