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

# ST_WithinCC

Computes spatial connected components across the entire dataframe using the `ST_Within` predicate. Two geometries are in the same component if the first geometry is completely within the second. Returns a component ID for each row.

<img src="https://mintcdn.com/wherobots/wLm_IRUSNlHZTHJP/images/sql-functions/ST_WithinCC/ST_WithinCC.svg?fit=max&auto=format&n=wLm_IRUSNlHZTHJP&q=85&s=29ed9d9d64250e3e54e16a7ab905689c" alt="ST_WithinCC" width="400" height="300" data-path="images/sql-functions/ST_WithinCC/ST_WithinCC.svg" />

* `geometry` is the geometry column to analyze.
* `partitionBy` is an optional column to partition the data before computing connected components. When provided, the spatial predicate is only evaluated between rows that share the same partition value. This can significantly improve performance on large datasets.

## Signatures

```sql theme={"system"}
ST_WithinCC(geometry: Geometry)
```

```sql theme={"system"}
ST_WithinCC(geometry: Geometry, partitionBy: Column)
```

## Parameters

<ParamField body="geometry" type="Geometry" required>
  The input geometry.
</ParamField>

<ParamField body="partitionBy" type="Column">
  The partition by value.
</ParamField>

## Return type

<ResponseField type="Long">
  The connected component ID for each row.
</ResponseField>

## Example

```sql theme={"system"}
SELECT ST_WithinCC(geom) FROM my_table
```

```
85899345920
```
