Use your query structure to get the closest edge to P and project a closest point P' from P on the edge with ST_ClosestPoint
:
SELECT edge.id,
ST_ClosestPoint(edge.geom, <P>) AS "P'"
FROM (
SELECT <edges_id> AS id,
<edges_geom> AS geom
FROM <edges_table>
ORDER BY ST_Distance(<P>, <edges_geom>)
LIMIT 1
) AS edge
Note: there might be better solutions if you are actually interested in the distance along the line to the line's node you need as an entry point for routing.
EDITUPDATE:
ST_Distance
in conjunction with LatLon (e.g. EPSG:4326) is a tricky business. While it might work here, with sufficiently small distances, do at least not use it to derive metric distances (this does equally apply to the KNN operators, e.g. <->
). For a more robust and precise solution, consider casting to geography prior to the calculations (e.g. ST_Distance(<P>::geography, <edges_geom>::geography)
)