> ## Documentation Index
> Fetch the complete documentation index at: https://docs.cockroachlabs.com/llms.txt
> Use this file to discover all available pages before exploring further.

# ST_Touches

Given two shapes *A* and *B*, `ST_Touches(A, B)` returns `true` if both the following are true:

* At least one point in the set of points that comprises *A* is also a member of the set of points that make up *B*.
* No points that make up the interior of *A* are also part of the interior of *B*.

In other words, *A* and *B* have a point along their boundaries in common (i.e., they "touch"), but none of their interior points intersect.  This distinction between shapes touching along a boundary vs. intersecting is also made by the [DE-9IM](https://docs.cockroachlabs.com/docs/stable/architecture/glossary.md#de-9im) standard.

`ST_Touches` works on the following data types:

* [`GEOMETRY`](https://docs.cockroachlabs.com/docs/stable/architecture/glossary#geometry)

> [!NOTE]
>
> \`\` will attempt to use any available [spatial index](https://docs.cockroachlabs.com/docs/stable/spatial-indexes.md) to speed up its operation.  Use the prefixed variant `_` if you do not want any spatial indexes to be used.

## Examples

> [!NOTE]
>
> The screenshots in these examples were generated using [geojson.io](http://geojson.io), but they are designed to showcase the shapes, not the map.  Representing `GEOMETRY` data in GeoJSON can lead to unexpected results if using geometries with [SRIDs](https://docs.cockroachlabs.com/docs/stable/architecture/glossary.md#srid) other than 4326 (as shown below).

### True

In this example, \`\` returns `true` because both of the following are true:

* At least one point in the set of Points that comprise Polygon *A* is a member of the set of points that make up the LineString *B*.
* No points from the interior of *A* are also part of the interior of *B*.

```sql theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
SELECT st_touches(st_geomfromtext('SRID=4326;POLYGON((-87.906471 43.038902, -95.992775 36.153980, -75.704722 36.076944, -87.906471 43.038902), (-87.623177 41.881832, -90.199402 38.627003, -82.446732 38.413651, -87.623177 41.881832))'), st_geomfromtext('SRID=4326;LINESTRING(-87.623177 41.881832, -90.199402 38.627003, -82.446732 38.413651, -87.623177 41.881832)'));
```

```
   st_touches
---------------
     true

(1 row)
```

![ST\_Touches - true](https://mintcdn.com/cockroachlabs/bBD0UEapbn6fk8Rb/images/common/geospatial/st_touches_true.png?fit=max\&auto=format\&n=bBD0UEapbn6fk8Rb\&q=85\&s=337a2712ca19e8a837d037cac7cde2dc)

### False

In this example, \`\` returns `false` because:

* Some points from the interior of the LineString *B* are also part of the interior of the Polygon *A*.

```sql theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
SELECT st_touches(st_geomfromtext('SRID=4326;POLYGON((-87.906471 43.038902, -95.992775 36.153980, -75.704722 36.076944, -87.906471 43.038902))'), st_geomfromtext('SRID=4326;LINESTRING(-88.243385 40.116421, -87.906471 43.038902, -95.992775 36.153980, -95.235278 38.971667)'));
```

```
   st_touches
---------------
     false
(1 row)
```

![ST\_Touches - false](https://mintcdn.com/cockroachlabs/bBD0UEapbn6fk8Rb/images/common/geospatial/st_touches_false.png?fit=max\&auto=format\&n=bBD0UEapbn6fk8Rb\&q=85\&s=c9a57b7e1705ebb10e7c01dff65a4e4b)

## See also

* [Spatial and GIS Glossary of Terms](https://docs.cockroachlabs.com/docs/stable/architecture/glossary.md)
* [Spatial indexes](https://docs.cockroachlabs.com/docs/stable/spatial-indexes.md)
* [Spatial functions](https://docs.cockroachlabs.com/docs/stable/functions-and-operators.md#spatial-functions)
* [`ST_Covers`](https://docs.cockroachlabs.com/docs/stable/st_covers)
* [`ST_CoveredBy`](https://docs.cockroachlabs.com/docs/stable/st_coveredby)
* [`ST_Contains`](https://docs.cockroachlabs.com/docs/stable/st_contains)
* [`ST_Within`](https://docs.cockroachlabs.com/docs/stable/st_within)
* [`ST_Intersects`](https://docs.cockroachlabs.com/docs/stable/st_intersects)
* [`ST_CoveredBy`](https://docs.cockroachlabs.com/docs/stable/st_coveredby)
* [`ST_Covers`](https://docs.cockroachlabs.com/docs/stable/st_covers)
* [`ST_Disjoint`](https://docs.cockroachlabs.com/docs/stable/st_disjoint)
* [`ST_Equals`](https://docs.cockroachlabs.com/docs/stable/st_equals)
* [`ST_Overlaps`](https://docs.cockroachlabs.com/docs/stable/st_overlaps)
* [`ST_ConvexHull`](https://docs.cockroachlabs.com/docs/stable/st_convexhull)
* [`ST_Union`](https://docs.cockroachlabs.com/docs/stable/st_union)
* [Migrate from Shapefiles](https://docs.cockroachlabs.com/docs/stable/migrate-from-shapefiles.md)
* [Migrate from GeoJSON](https://docs.cockroachlabs.com/docs/stable/migrate-from-geojson.md)
* [Migrate from GeoPackage](https://docs.cockroachlabs.com/docs/stable/migrate-from-geopackage.md)
* [Migrate from OpenStreetMap](https://docs.cockroachlabs.com/docs/stable/migrate-from-openstreetmap.md)
* [Introducing Distributed Spatial Data in CockroachDB](https://www.cockroachlabs.com/blog/spatial-data/) (blog post)
