By using db<>fiddle, you agree to license everything you submit by Creative Commons CC0.
create table t (loc point);
insert into t (loc) values
(POINT(10, 0)),
(POINT(15, 20)),
(POINT(50, 50));
Records: 3 Duplicates: 0 Warnings: 0
select ST_AsText(t.loc) as point,
ST_Distance(loc, POINT(49, 49)) as dist
from t
order by ST_Distance(loc, POINT(49, 49))
limit 2;
point | dist |
---|---|
POINT(50 50) | 1.4142135623730951 |
POINT(15 20) | 44.68780594300866 |