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

# ST_Touches

export const InternalLink = ({version, path = "", children, ...props}) => {
  let detectedVersion = version || "stable";
  if (typeof window !== 'undefined' && !version) {
    const match = window.location.pathname.match(/\/docs\/([^/]+)/);
    if (match) {
      detectedVersion = match[1];
    }
  }
  const normalizedPath = path.startsWith("/") ? path.slice(1) : path;
  return <a href={`/docs/${detectedVersion}/${normalizedPath}`} {...props}>
      {children}
    </a>;
};

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 <InternalLink path="architecture/glossary#de-9im">DE-9IM</InternalLink> standard.

`ST_Touches` works on the following data types:

* <InternalLink path="architecture/glossary#geometry">`GEOMETRY`</InternalLink>

<Note>
  `ST_Touches` will attempt to use any available <InternalLink path="spatial-indexes">spatial index</InternalLink> to speed up its operation.
  Use the prefixed variant `_ST_Touches` if you do not want any spatial indexes to be used.
</Note>

## 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 <InternalLink path="architecture/glossary#srid">SRIDs</InternalLink> other than 4326 (as shown below).
</Note>

### True

In this example, `ST_Touches` 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)'));
```

```text theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
   st_touches
---------------
     true

(1 row)
```

<img src="https://mintcdn.com/cockroachlabs/-7uTB1VKbyjy3gp4/images/v24.3/geospatial/st_touches_true.png?fit=max&auto=format&n=-7uTB1VKbyjy3gp4&q=85&s=4b3bd8e0285441201f7167f7ad921e2d" alt="ST_Touches - true" width="1280" height="988" data-path="images/v24.3/geospatial/st_touches_true.png" />

### False

In this example, `ST_Touches` 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)'));
```

```text theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
   st_touches
---------------
     false
(1 row)
```

<img src="https://mintcdn.com/cockroachlabs/Ww46ooILgIVlX3C1/images/v24.3/geospatial/st_touches_false.png?fit=max&auto=format&n=Ww46ooILgIVlX3C1&q=85&s=6818293e2f1f42154f5b30da9ba605e5" alt="ST_Touches - false" width="1280" height="988" data-path="images/v24.3/geospatial/st_touches_false.png" />

## See also

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