create function are_close_to_each_other(g1 geometry, g2 geometry)
returns boolean
language sql immutable as $$
select ST_DWithin(g1, g2, 100);
$$;
select x.*, y.*
from sometable x, sometable y
where are_close_to_eachother(x.geom, y.geom);
I have an index on sometable (geom). Will this index be used inside function are_close_to_each_other? If not, how to make it use it?
st_dwithin
isparallel safe
, your function isunsafe
(by default), so while the spatial index will be used, the seq scan on the 1st table will be much slower when using your function rather than joining onst_dwithin
directly