ST_Length()

Returns a line geometry’s length: Cartesian units by default, or meters for SRID 4326.

Syntax

ST_Length(geom)
ST_Length(geom, srid)

Aliases: none.

Arguments

geom is GEOMETRY or GEOMETRY32; srid is an INT64 computation override.

Return Value

Returns FLOAT64 for GEOMETRY and FLOAT32 for GEOMETRY32.

Usage Notes

  • Input must be LINESTRING or MULTILINESTRING; other geometry types are rejected.

  • SRID 4326 uses geodesic meters; other supported SRIDs use Cartesian units. The optional SRID overrides the geometry SRID and is range-checked.

Examples

DROP DATABASE IF EXISTS geo_length_demo;
CREATE DATABASE geo_length_demo;
USE geo_length_demo;

SELECT ST_Length(ST_GeomFromText('LINESTRING(0 0, 3 4)')) AS cartesian_length,
       ST_Length(ST_GeomFromText('LINESTRING(0 0, 1 0)'), 4326) AS geodesic_meters;

DROP DATABASE geo_length_demo;

See Also

ST_Area(), ST_Distance().