Boone Putney bio photo

Boone Putney

Software Development
Random Musings
Austin, Texas

HumanPlanet Soleer

Email LinkedIn Github

If you need to do any dynamic distance calculations within a PostgreSQL database, I highly recommend the earthdistance module. We are currently using it for locating and sorting target entities within a set radius using geocoded addresses. Earthdistance takes care of all of the heavy lifting, and allows for much more efficient queries.

Here’s how you enable it within PostgreSQL:

 1 #from shell, login to PostgresSQL server
 2 sudo -u postgres psql
 3 
 4 #list available databases
 5 postgres=# \list
 6 
 7 #login to target database
 8 postgres=# \connect my_database
 9 
10 #enable cube extension (required by earthdistance)
11 my_database=# CREATE EXTENSION cube;
12 
13 #enable earthdistance extension
14 my_database=# CREATE EXTENSION earthdistance;