There is the famous ST_ClosestPoint() return the closest point inside polygon to some outside point.
I'm looking the inverse problem: I have a location inside polygon, and I want to get the closest location outside the polygon.
I started thinking that first step should be to find the closest point on the boundary of the polygon. Although I don't know how to achieve this, I'm not sure how to continue even from this stage (considering I have the closest boundary point to my inside point).
EDIT: What about comparing results from ST_Line_Locate_Point() running on all lines of the polygon and choosing the minimum: This gives me the closest point on the border line
WITH border_closest_points AS ( SELECT ST_Line_Locate_Point(border_lines.geom, ST_GeomFromText('POINT(lon lat)', 4326)) AS fraction, ST_Line_Interpolate_Point(border_lines.geom, ST_Line_Locate_Point(border_lines.geom, ST_GeomFromText('POINT(lon lat)', 4326))) AS closest_point_on_line FROM border_lines ) SELECT border_closest_points.closest_point_on_line AS geom, ST_Distance(ST_GeomFromText('POINT(lon lat)', 4326), border_closest_points.closest_point_on_line) AS distance FROM border_closest_points ORDER BY distance ASC LIMIT 1;