Radius search in PostgreSQL may come in employing a light and/or a much more sophisticated version. This article discusses the light one, namely the
cube and the
earth distance extensions, most probably sufficient for the web user’s getting here and there requirements.
earth distance, depending on
cube, assumes the earth to be perfectly spherical, anyone demanding a higher accuracy level, especially for the mountainous parts, may take a look at the PostGIS project.
Although radius search, the light variety, will be up fast and performing well, there may be some mantrap around, for the ones who prefer to read documentation the easy way too. First of all, PostgreSQL: Documentation: 9.1: earthdistance indicates that the
point-based earth distance calculation is hard-wired to statute miles in units. You may use this circumstance to your advantage, like datachomp did in Radius Queries in Postgres, as long as you know what you’re doing. Second to that, taking on the alternate
cube-based earth distance calculation, the
earth_box function, accepting a lat/long and a radius on input, may return locations farther than the actual radius given (documented alike). This is because
earth_box, as the name implies, still handles a box geometry on the idealized sphere (and not some higher order circle surface). But more on that below.