you can extract the exterior of the polygon (st_boundary), use linear referencing function st_lineLocatePoint to find the projection of line's start and end points then add the points to the line:
with pg as (
select 'POLYGON((0 0, 5 0, 3 5, 0 0))'::geometry as geom
), line as (
select 'LINESTRING(1 1, 2 1, 3.5 2)'::geometry as geom
) select st_addPoint(st_addPoint(
line.geom,
st_lineinterpolatepoint(
st_boundary(pg.geom),
st_lineLocatePoint(st_boundary(pg.geom), st_startpoint(line.geom))),
0),
st_lineinterpolatepoint(
st_boundary(pg.geom),
st_lineLocatePoint(st_boundary(pg.geom), st_endpoint(line.geom))),
st_numpoints(line.geom) + 1)
from pg, line;
(a smarter way must exist, but linear referencing function are quite efficient to find/build points)