PostGISGeometry Accessors

ST_NumInteriorRings

What is ST_NumInteriorRings?

ST_NumInteriorRings is a PostGIS function that returns the number of interior rings (holes) in a single POLYGON. Non-polygon input (including MULTIPOLYGON) returns NULL.

SQL
ST_NumInteriorRings(geometry polygon)integer

Pair with ST_InteriorRingN (1-based) for direct access, or ST_DumpRings for set-style iteration over every ring.

When would you use ST_NumInteriorRings?

Use ST_NumInteriorRings to filter polygons with or without holes, or to bound a loop that accesses rings by index:

SQL
1SELECT id, ST_NumInteriorRings(geom) AS hole_count
2FROM parcels
3WHERE GeometryType(geom) = 'POLYGON'
4  AND ST_NumInteriorRings(geom) > 0;

Useful for data quality checks (polygons that unexpectedly contain holes may indicate a digitization issue) and for computing "net" area: ST_Area(shell) - sum of ST_Area(hole_polygons) — though ST_Area already accounts for holes automatically.

FAQs

Does ST_NumInteriorRings work on MultiPolygon?

No — returns NULL. Unpack with ST_Dump first, then apply per component.

Is there an alias?

Yes — ST_NumInteriorRing (without the trailing "s") is accepted as a synonym in some versions, though the plural form is canonical.

What is the difference from ST_NRings?

ST_NumInteriorRings returns only the hole count of a single polygon. ST_NRings returns the total ring count (exterior plus interior) across a whole multipolygon.

Does ST_Area already subtract holes?

Yes. ST_Area computes net area, accounting for holes. You do not need to subtract hole areas manually.