U kunt de afstandsfunctie toepassen met de operator <->
direct in de ORDER BY
clausule. Daarbij gebruikt de planner de gist-index:
EXPLAIN (ANALYSE,COSTS OFF)
SELECT * FROM data
ORDER BY geog <-> ST_Point(6.5, 48.7)
LIMIT 13;
QUERY PLAN
----------------------------------------------------------------------
Limit (actual time=15.019..15.213 rows=13 loops=1)
-> Index Scan using idx_data_point on data (actual time=15.017..15.210 rows=13 loops=1)
Order By: (geog <-> '0101000020E61000000000000000001A409A99999999594840'::geography)
Planning Time: 0.372 ms
Execution Time: 15.309 ms
Demo:db<>fiddle