POSTGIS limiting a distance query by a threshold
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}
1
I am looking to get pairwise distances between rows from two tables and only return the pairs that are within a threshold distance. The tables have large numbers of objects so performance is a concern. I found an example of getting the closest distances at PostGIS minimum distance between two large sets of points The code there looks like SELECT a.id, nn.id AS id_nn, a.geom, nn.geom_closest, ST_Distance_Sphere(a.geom, nn.geom_closest) AS min_dist FROM table_a AS a CROSS JOIN LATERAL (SELECT b.id, b.geom AS geom_closest FROM table_b b ORDER BY a....