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

> Replace complete sets of H3 child cells with their parents.

Compacts an array of H3 cell IDs using H3's [compactCells(cells)](https://h3geo.org/docs/api/hierarchy#compactcells).

Complete sets of child cells are replaced by their parents recursively. Cells that cannot be compacted are retained. The result may contain cells at different resolutions and represents the same set of cells when expanded to the original resolution with `ST_H3Uncompact`.

Input cells must be unique, valid H3 cell IDs at the same resolution. H3 errors are propagated. An empty array returns an empty array, and a null array returns null. The order of the returned cells is not guaranteed.

## Signature

```sql theme={"system"}
ST_H3Compact(cells: Array<Long>)
```

## Return type

`Array<Long>`

## Examples

Compact the 49 resolution 7 descendants of a resolution 5 hexagon back to their ancestor:

```sql theme={"system"}
SELECT ST_H3Compact(ST_H3ToChildren(601041811137363967, 7))
```

Output:

```text theme={"system"}
[601041811137363967]
```

A single cell is retained:

```sql theme={"system"}
SELECT ST_H3Compact(array(601041811137363967))
```

Output:

```text theme={"system"}
[601041811137363967]
```


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.