All Products
Search
Document Center

ApsaraDB RDS:ST_LineSubstring

Last Updated:Mar 28, 2026

Returns a substring of a LineString between two fractional positions along its length.

Syntax

geometry  ST_LineSubstring(geometry  aLinestring, float8 startfraction, float8 endfraction);
geography ST_LineSubstring(geography aLinestring, float8 startfraction, float8 endfraction);

Parameters

ParameterTypeDescription
aLinestringgeometry / geographyThe input LineString.
startfractionfloat8The start position.
endfractionfloat8The end position.

Usage notes

  • Equal fractions: If startfraction and endfraction are equal, the function behaves the same as ST_LineInterpolatePoint.

  • MultiLineString: ST_LineSubstring operates on a single LineString. To extract a substring from a MultiLineString, first merge its component lines with ST_LineMerge.

  • 3D and M coordinates: The function preserves z and m coordinates.

  • geometry vs. geography: The geometry variant measures fractions along a planar (straight-line) path. The geography variant measures along the spheroid surface, so the interpolated coordinates differ even for the same input.

Examples

Geometry

Extract the middle 30% of a line (from 30% to 60% of its length):

SELECT ST_AsText(ST_LineSubstring('LINESTRING(0 0,10 10)'::geometry, 0.3, 0.6));
      st_astext
---------------------
 LINESTRING(3 3,6 6)
(1 row)

Geography

The same fractions applied to a geography object return spheroid-interpolated coordinates:

SELECT ST_AsText(ST_LineSubstring('LINESTRING(0 0,10 10)'::geography, 0.3, 0.6));
                                   st_astext
--------------------------------------------------------------------------------
 LINESTRING(2.97227762767668 3.01417970957332,5.96094221033023 6.0199989936211)

What's next