To get the 5 closest:
SELECT * FROM your_table ORDER BY ST_Distance(your_table.geom, ST_Geomfromtext(your point as wkt)) limit 5;
If you have a large data set and you know that you do not want to search further, say, 1 km, the query will be more efficient if you run:
SELECT * FROM your_table WHERE ST_DWithin(your_table.geom, ST_Geomfromtext(your point as wkt, 1000) ORDER BY ST_Distance(your_table.geom, ST_Geomfromtext(your point as wkt)) limit 5;
/ Niklas
Nicklas avén
source share