> ## 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_Contains

Given two shapes *A* and *B*, the predicate function `ST_Contains(A, B)` returns `true` if:

* No point in *B* lies outside of shape *A*, and
* At least one point in the interior of *B* lies in the interior of *A*.

In other words, the exterior of shape *A* must not include any point in *B*, and one or more points of *B*'s interior must lie in the interior of *A*.

This behavior is similar to [`ST_Covers`](/docs/stable/st_covers), except that the criteria are more exacting, and therefore some pairs of shapes will be rejected by this function that would be accepted by `ST_Covers`.

`ST_Contains` works on the following data types:

* [`GEOMETRY`](/docs/stable/architecture/glossary#geometry)

> [!NOTE]
>
> \`\` will attempt to use any available [spatial index](/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.

> [!NOTE]
>
> This function is the inverse of [`ST_Within`](/docs/stable/st_within).

## 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](/docs/stable/architecture/glossary.md#srid) other than 4326 (as shown below).

### True

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

* No point in the LineString *B* lies outside of the Polygon *A*, and
* At least one point in the interior of *B* lies in the interior of *A*.

```sql theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
SELECT ST_Contains(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)'));
```

```
  st_contains
---------------
     true

(1 row)
```

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

### False

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

* At least one point in the interior of LineString *B* does not lie in the interior of the Polygon *A*.

Note that A query against these shapes with [`ST_Covers`](/docs/stable/st_covers) will return `true`.

```sql theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
SELECT st_contains(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( -87.906471 43.038902, -95.992775 36.153980)'));
```

```
  st_contains
---------------
     false
(1 row)
```

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

## See also

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