Return the H3 parent cell that contains a given cell at a coarser resolution.
H3_CELL_TO_PARENT(cell, resolution)
## Overview Returns the ancestor H3 cell that contains the given cell at a coarser resolution. Every cell at resolution N is contained by exactly one cell at each coarser resolution from 0 to N-1, and this function walks that hierarchy. It is the inverse direction of H3_CELL_TO_CHILDREN and is the standard way to downsample or re-aggregate H3-indexed data to a coarser granularity. Use this when rolling event-level H3 buckets up into regional summaries, when bringing two cells at different resolutions to a common comparison level, or when building hierarchical dashboards that zoom from continent down to neighborhood. ## Behavior - Returns a BIGINT cell ID at the target resolution. - Returns NULL if the target resolution is equal to or finer than the child's resolution. - Returns NULL if the target resolution is outside [0, 15] or if the input cell is NULL or invalid. - The result is deterministic: every cell at resolution N maps to exactly one cell at each coarser resolution. - Parent containment is strict: H3_CONTAINS_FAST(parent, cell) is always true for the pair (H3_CELL_TO_PARENT(cell, r), cell). - Because of pentagon cells, not every path from fine to coarse is symmetric, but parent lookup is always well-defined. ## H3 resolution reference | Res | Average edge length | Average hex area | | --- | --- | --- | | 0 | 1,107 km | 4.25 million km^2 | | 5 | 8.54 km | 253 km^2 | | 7 | 1.22 km | 5.16 km^2 | | 9 | 174 m | 0.11 km^2 | | 12 | 9.4 m | 307 m^2 | ## Compatibility - Follows the standard H3 hierarchical hex grid specification for parent lookups.
| Name | Type | Description |
|---|---|---|
cell | Specifies the child H3 cell index. Must be a valid H3 cell. | |
resolution | Specifies the target coarser resolution. Valid values are integers from 0 through the child's resolution - 1. Finer or equal resolutions return NULL. |
-- Roll a resolution 9 cell up to its resolution 8 parent.
SELECT H3_CELL_TO_PARENT(H3_LATLNG_TO_CELL(40.7128, -74.0060, 9), 8) AS parent;
-- Re-aggregate resolution 9 events into resolution 7 cells for a regional dashboard.
SELECT
H3_CELL_TO_PARENT(h3_res9, 7) AS h3_res7,
SUM(events) AS events
FROM analytics.curated.h3_events_res9
GROUP BY H3_CELL_TO_PARENT(h3_res9, 7);
-- Two cells at different resolutions cannot be compared directly; roll both to a shared parent.
WITH pts AS (
SELECT H3_LATLNG_TO_CELL(40.70, -74.00, 9) AS a,
H3_LATLNG_TO_CELL(40.71, -74.01, 8) AS b
)
SELECT
H3_CELL_TO_PARENT(a, 7) AS a_parent_res7,
H3_CELL_TO_PARENT(b, 7) AS b_parent_res7,
H3_CELL_TO_PARENT(a, 7) = H3_CELL_TO_PARENT(b, 7) AS share_parent
FROM pts;
-- Starting at a resolution 10 cell, show its ancestors at every coarser level.
WITH base AS (SELECT H3_LATLNG_TO_CELL(51.5074, -0.1278, 10) AS cell)
SELECT
cell AS res10,
H3_CELL_TO_PARENT(cell, 9) AS res9,
H3_CELL_TO_PARENT(cell, 7) AS res7,
H3_CELL_TO_PARENT(cell, 5) AS res5,
H3_CELL_TO_PARENT(cell, 0) AS res0
FROM base;
-- Cell is resolution 5; asking for parent at resolution 7 (finer) returns NULL.
SELECT H3_CELL_TO_PARENT(H3_LATLNG_TO_CELL(51.5, -0.1, 5), 7) AS parent;