ST_DISTANCE()

All functions > GEOSPATIAL > ST_DISTANCE()

Returns the minimum distance between two geometries or geographies.

Signatures

Distance

Returns: Distance between the two inputs

ST_DISTANCE(geo1: T, geo2: T) → DOUBLE
sql
ParameterTypeRequiredDescription
geo1TYesFirst geometry or geography
geo2TYesSecond geometry or geography

With:

  • T : Custom types: GEOM_POINT | GEOM_LINESTRING | GEOM_POLYGON | GEOM_MULTIPOINT | GEOM_MULTILINESTRING | GEOM_MULTIPOLYGON | GEOM_MULTIANY | GEOG_POINT | GEOG_LINESTRING | GEOG_POLYGON | GEOG_MULTIPOINT | GEOG_MULTILINESTRING | GEOG_MULTIPOLYGON | GEOG_MULTIANY

Signature notes:

  • On GEOMETRY: returns planar Euclidean distance in the coordinate units of the SRID
  • On GEOGRAPHY: returns ellipsoid / great-circle distance in meters; numeric results often show many fractional digits, but real-world position error is usually far larger than those decimals imply
  • Accepts any sub kind combination (point to point, point to polygon, polygon to polygon, etc.)
  • Returns 0.0 when the inputs overlap or touch
  • Both inputs must be the same type family (both GEOMETRY or both GEOGRAPHY); mixing is a type error
  • Returns NULL if either input is NULL

Examples

Geometry (planar distance)

FeatureQL
SELECT
    f1 := ST_DISTANCE(ST_GEOMPOINT(0.0, 0.0), ST_GEOMPOINT(3.0, 4.0)) -- Euclidean distance between two points
;
Result
f1 VARCHAR
5.0

Geography (spherical distance in meters)

FeatureQL
SELECT
    f1 := ST_DISTANCE(ST_GEOGPOINT(-122.4194, 37.7749), ST_GEOGPOINT(-118.2437, 34.0522)) -- San Francisco to Los Angeles, approximately 559 km (geography distance in meters)
;
Result
f1 VARCHAR
559042.33650

Last update at: 2026/05/26 17:22:09