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
dimension.
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.
Note
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.
Note
By default, ST_LineStringAggr uses the original format for a geometry, if it is available. Otherwise, the internal format
is used. For more information about internal and original formats, see STORAGE FORMAT clause, CREATE SPATIAL REFERENCE SYSTEM statement.
The following example returns the result LineString (0 0, 2 0, 1 1).
BEGIN
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 )
FROM t_points;
END