- Categories:
ST_DISTANCE¶
Returns the minimum geodesic distance (in meters) between two geospatial objects.
Syntax¶
ST_DISTANCE( <geography_expression_1> , <geography_expression_2> )
Arguments¶
geography_expression_1
The argument must be an expression of type GEOGRAPHY.
geography_expression_2
The argument must be an expression of type GEOGRAPHY.
Returns¶
Returns a value of type REAL that represents distance in meters.
Usage Notes¶
Returns NULL if one or more input points are NULL.
Examples¶
This shows the distance in meters between two points 1 degree apart along the equator (approximately 111 kilometers or 69 miles).
WITH d AS ( ST_DISTANCE(ST_MAKEPOINT(0, 0), ST_MAKEPOINT(1, 0)) ) SELECT d / 1000 AS kilometers, d / 1609 AS miles; +---------------+--------------+ | KILOMETERS | MILES | |---------------+--------------| | 111.195101177 | 69.108204585 | +---------------+--------------+
This shows use of the ST_DISTANCE function with NULL values:
SELECT ST_DISTANCE(ST_MAKEPOINT(0, 0), ST_MAKEPOINT(NULL, NULL)); +-----------------------------------------------------------+ | ST_DISTANCE(ST_MAKEPOINT(0, 0), ST_MAKEPOINT(NULL, NULL)) | |-----------------------------------------------------------| | NULL | +-----------------------------------------------------------+