

 Amazon Redshift will no longer support the creation of new Python UDFs starting Patch 198. Existing Python UDFs will continue to function until June 30, 2026. For more information, see the [ blog post ](https://aws.amazon.com/blogs/big-data/amazon-redshift-python-user-defined-functions-will-reach-end-of-support-after-june-30-2026/). 

# ST\$1Distance
<a name="ST_Distance-function"></a>

For input geometries, ST\$1Distance returns the minimum Euclidean distance between the 2D projections of the two input geometry values. 

For 3DM, 3DZ, 4D geometries, ST\$1Distance returns the Euclidean distance between the 2D projections of two input geometry values.

For input geographies, ST\$1Distance returns the geodesic distance of the two 2D points. The unit of distance is in meters. For geographies other than points and empty points an error is returned.

## Syntax
<a name="ST_Distance-function-syntax"></a>

```
ST_Distance(geo1, geo2)
```

## Arguments
<a name="ST_Distance-function-arguments"></a>

 *geo1*   
A value of data type `GEOMETRY` or `GEOGRAPHY`, or an expression that evaluates to a `GEOMETRY` or `GEOGRAPHY` type. The data type of *geo1* must be the same as *geo2*.

 *geo2*   
A value of data type `GEOMETRY` or `GEOGRAPHY`, or an expression that evaluates to a `GEOMETRY` or `GEOGRAPHY` type. The data type of *geo2* must be the same as *geo1*.

## Return type
<a name="ST_Distance-function-return"></a>

`DOUBLE PRECISION` in the same units as the input geometries or geographies.

If *geo1* or *geo2* is null or empty, then null is returned. 

If *geo1* and *geo2* don't have the same value for the spatial reference system identifier (SRID), then an error is returned. 

If *geo1* or *geo2* is a geometry collection, then an error is returned. 

## Examples
<a name="ST_Distance-function-examples"></a>

The following SQL returns the distance between two polygons. 

```
SELECT ST_Distance(ST_GeomFromText('POLYGON((0 2,1 1,0 -1,0 2))'), ST_GeomFromText('POLYGON((-1 -3,-2 -1,0 -3,-1 -3))'));
```

```
  st_distance
-----------
1.4142135623731
```

The following SQL returns the distance (in meters) between the Brandenburg Gate and the Reichstag building in Berlin using a GEOGRAPHY data type. 

```
SELECT ST_Distance(ST_GeogFromText('POINT(13.37761826722198 52.516411678282445)'), ST_GeogFromText('POINT(13.377950831464005 52.51705102546893)'));
```

```
   st_distance
------------------
 74.64129172609631
```