Getting all Buildings in range of 5 miles from specified coordinates

Why are you storing x,y in separated columns? I strongly suggest you to store them as geometry or geography to avoid unnecessary casting overhead in query time. That being said, you can compute and check distances in miles using ST_DWithin or ST_Distance: (Test data) CREATE TABLE building (name text, long numeric, lat numeric); INSERT INTO … Read more