This may be more of a SQL fundamentals question but I'm sure somebody on here has encountered this before.
I have a database of geospacial data (around 4 million points) using PostgreSQL/PostGIS
I would like to add a value to indicate how many of the other points in the table are within a specified range (5km) to that row value.
SELECT count(geom)
FROM geom_points
WHERE ST_DistanceSphere(geom, ST_SetSRID(ST_MakePoint(long, lat),4326)) < 5000
The following works for a single row but I would like to be able to run this value for all rows and append the value to the row as a count.
I'm not really worried how long it will take as it is a function I intend to run once per year.
How do I achieve this?