SELECT p.id AS point_id, b.id AS road_id, ST_DISTANCE(b.geom, p.geom) AS distance
FROM points p
CROSS JOIN LATERAL (
SELECT r.id AS id, r.geom AS geom
FROM roads r
ORDER BY r.geom <-> p.geom
LIMIT 1
) b;
SELECT osm_id, highway, name, tags, ST_DISTANCE(way, point) AS Distance
FROM public.planet_osm_line
INNER JOIN (SELECT ST_TRANSFORM( ST_SetSRID(ST_POINT(48.323, 54.263), 4326), 900913) AS point ) AS p
ON ST_DWithin(point, way, 200)
WHERE highway IS NOT NULL AND name IS NOT NULL
ORDER BY Distance
LIMIT 1;