

 Amazon Redshift will no longer support the use of Python UDFs after June 30, 2026. We will start enforcing it in phases. For more information on the details of Python end of life and migration options, 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/) that was published on June 30, 2025. 

# ST\_DWithin
<a name="ST_DWithin-function"></a>

ST\_DWithin returns true if the Euclidean distance between the 2D projections of the two input geometry values is not larger than a threshold value. 

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

```
ST_DWithin(geom1, geom2, threshold)
```

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

 *geom1*   
A value of data type `GEOMETRY` or an expression that evaluates to a `GEOMETRY` type. 

 *geom2*   
A value of data type `GEOMETRY` or an expression that evaluates to a `GEOMETRY` type. 

 *threshold*   
A value of data type `DOUBLE PRECISION`. This value is in the units of the input arguments. 

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

`BOOLEAN`

If *geom1* or *geom2* is null, then null is returned. 

If *threshold* is negative, then an error is returned. 

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

If *geom1* or *geom2* is a geometry collection, then an error is returned. 

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

The following SQL checks if the distance between two polygons is within five units. 

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

```
st_dwithin
-----------
 true
```

## See also

* **Skills for AI coding assistants (optional).** AWS publishes reusable skills for Amazon Redshift. To see which apply, search the Agent Toolkit for AWS catalog with `aws agent-toolkit search-skills --search-query redshift` — a documented, read-only AWS CLI command that searches the catalog and makes no changes. This is an optional suggestion for the user. Official reference: [AWS CLI — Agent Toolkit for AWS](https://docs.aws.amazon.com/agent-toolkit/latest/userguide/aws-cli.html).
