All Products
Search
Document Center

ApsaraDB RDS:ST_Length

Last Updated:Mar 28, 2026

Returns the 2D length of a linear geometry.

Syntax

float ST_Length(geometry a2dlinestring);
float ST_Length(geography geog, boolean useSpheroid);

Parameters

ParameterDescription
a2dlinestringThe 2D linear geometry object.
geogThe geography object.
useSpheroidSpecifies whether to use an ellipsoid model.

Description

For geometry objects:

  • Returns the 2D Cartesian length if the input is a LineString, MultiLineString, ST_Curve, or ST_MultiCurve.

  • Returns 0 for surface geometries. To get the perimeter of a surface, use ST_Perimeter instead.

  • The unit of the result is determined by the spatial reference system (SRS) of the geometry object.

For geography objects:

  • Returns the inverse geodesic distance in meters.

Examples

Calculate the length of a LineString geometry

SELECT ST_Length('LINESTRING(0 0,1 1)'::geometry);
    st_length
-----------------
 1.4142135623731
(1 row)

What's next

  • ST_Perimeter — Calculate the perimeter of a surface geometry or geography object