- Categories:
ST_ DISTANCE¶
Returns the minimum great circle distance between two GEOGRAPHY or the minimum Euclidean distance between two GEOMETRY objects.
Syntax¶
Arguments¶
geography_or_geometry_expression_1The argument must be of type GEOGRAPHY or GEOMETRY.
geography_or_geometry_expression_2The argument must be of type GEOGRAPHY or GEOMETRY.
Returns¶
Returns a FLOAT value, which represents the distance, or NULL:
- For GEOGRAPHY input values, the distance is in meters.
- For GEOMETRY input values, the distance is computed with the same units used to define the input coordinates.
- Returns NULL if one or more input points are NULL.
Usage notes¶
- For GEOMETRY objects, the function reports an error if the two input GEOMETRY objects have different SRIDs.
Examples¶
The following examples use the ST_DISTANCE function.
GEOGRAPHY examples¶
Show the distance in meters between two points 1 degree apart along the equator (approximately 111 kilometers or 69 miles).
Show the output of the ST_DISTANCE function when one or more input values are NULL:
GEOMETRY examples¶
The following example compares the distance calculated for GEOGRAPHY and GEOMETRY input objects.
For additional examples, see Examples comparing the GEOGRAPHY and GEOMETRY data types.