In case not (have you checked the docs?), use a simple (K)NN search:
SELECT CASE WHEN ST_LineLocatePoint(geom, <point>) < 0.5
THEN source
ELSE target
END as node
FROM edges
ORDER BY
geom <-> <point>
LIMIT 1
;
ST_LineLocatePoint in the CASE finds the fraction of line length of the projected point from <point> on the closest edge.geom, and selects either source or target.
A spatial index on edges is mandatory.
You can outsource the <point> creation into a CTE if you want.
You could also wrap this up in a function, but note that for a batch solution on a table of points (or more than one point) you'd better CROSS JOIN LATERAL the points table/expression to a (K)NN subquery. See e.g.
SELECT id FROM ospr.ways_vertices_pgr ORDER BY the_geom <-> ST_SetSRID( ST_Point(-77.009003, 38.889931), 4326) limit 1– jbalk May 18 '20 at 20:17<->operator that aren't easily implemented in an extension. But that's only a guess. Writing a function for one point is fine, better use the inline SQL solution for batch searches. Note that you may get different results with your alternative, as a vertex may be closer to point even if the point is right next to an edge. – geozelot May 18 '20 at 20:24