
Julie D. answered 04/04/25
Personalized Guidance from Experienced Cybersecurity Specialist
You are correct to consider using use_spheroid=false for optimizing performance, especially with large datasets and ST_DWithin. The problem is with how you're passing the parameter.
If you are working with geography in PostGIS, you should use the 3-argument version of ST_DWithin with the use_spheroid option; if you want to specify use_spheroid, you should use the 4-argument version.
You have a syntax error, though, because use_spheroid=false is a positional argument in the function call rather than a named parameter in SQL.
Here’s the correct usage:
ST_DWithin(geog1, geog2, distance, false)
So your query should look like this:
SELECT
pois.objectid,
ST_Multi(ST_Union(polygon.coordinates)) as coords
INTO table3
FROM table1 as polygon
INNER JOIN table12 as pois
ON ST_DWithin(polygon.geog, pois.geog, 10 * 1609.34, false)
GROUP BY pois.objectid
LIMIT 1;
That false is the use_spheroid flag in the 4-argument version of ST_DWithin.