The ST_LineStringAggr aggregate method can be used to build a linestring out of a group of ordered points. All of the geometry
columns to be combined must have the same SRID. All of the points to be combined must be non-empty with the same coordinate
Rows where the point is NULL are not included.
Returns NULL for an empty group or a group containing no non-NULL values.
The resulting linestring has the same coordinate dimension as each point.
The ORDER BY clause should be specified to control the order of points within the linestring. If not present, the order of
points in the linestring will vary depending on the access plan selected by the query optimizer.
The following example returns the result LineString (0 0, 2 0, 1 1).
DECLARE LOCAL TEMPORARY TABLE t_points( pk INT PRIMARY KEY,
p ST_Point );
INSERT INTO t_points VALUES( 1, 'Point( 0 0 )' );
INSERT INTO t_points VALUES( 2, 'Point( 2 0 )' );
INSERT INTO t_points VALUES( 3, 'Point( 1 1 )' );
SELECT ST_LineString::ST_LineStringAggr( p ORDER BY pk )