ST_AddPoint — Add a point to a LineString.
geometry ST_AddPoint(geometry linestring, geometry point
geometry ST_AddPoint(geometry linestring, geometry point, integer position = -1
Adds a point to a LineString before the index
(using a 0-based index).
position parameter is omitted or is -1
the point is appended to the end of the LineString.
This function supports 3d and will not drop the z-index.
Add a point to the end of a 3D line
SELECT ST_AsEWKT(ST_AddPoint('LINESTRING(0 0 1, 1 1 1)', ST_MakePoint(1, 2, 3))); st_asewkt ---------- LINESTRING(0 0 1,1 1 1,1 2 3)
Guarantee all lines in a table are closed by adding the start point of each line to the end of the line only for those that are not closed.
UPDATE sometable SET geom = ST_AddPoint(geom, ST_StartPoint(geom)) FROM sometable WHERE ST_IsClosed(geom) = false;