📣
TiDB Cloud Premium is now in public preview. Unlimited growth, instant elasticity, advanced security for enterprise workloads. Try it out →

ST_DISTANCE



Returns the minimum distance between two objects. For GEOMETRY inputs, the function uses Euclidean distance. For GEOGRAPHY inputs, the function uses haversine distance.

Syntax

ST_DISTANCE(<geometry_or_geography1>, <geometry_or_geography2>)

Arguments

ArgumentsDescription
<geometry_or_geography1>The argument must be an expression of type GEOMETRY or GEOGRAPHY and must contain a Point.
<geometry_or_geography2>The argument must be an expression of type GEOMETRY or GEOGRAPHY and must contain a Point.

Return Type

Double.

Examples

GEOMETRY examples

SELECT ST_DISTANCE( TO_GEOMETRY('POINT(0 0)'), TO_GEOMETRY('POINT(1 1)') ) AS distance ┌─────────────┐ │ distance │ ├─────────────┤ │ 1.414213562 │ └─────────────┘

GEOGRAPHY examples

SELECT ST_DISTANCE( ST_GEOGFROMWKT('POINT(0 0)'), ST_GEOGFROMWKT('POINT(1 0)') ) AS distance ╭──────────────────╮ │ distance │ ├──────────────────┤ │ 111195.080233533 │ ╰──────────────────╯

Was this page helpful?