ST_NumInteriorRing
ST_NumInteriorRing takes a polygon as an input parameter and returns the number of its interior rings.
If the given polygon is null or is empty, then null is returned.
If the polygon has no interior rings, then 0 (zero) is returned.
Syntax
Parameter
- polygon
- A value of type ST_Polygon that represents the polygon for which the number of interior rings is returned.
Return type
INTEGER
Example
The following example creates two
polygons:
- One with two interior rings
- One without any interior rings
SET CURRENT FUNCTION PATH = CURRENT FUNCTION PATH, db2gse
CREATE TABLE sample_polys (id INTEGER, geometry ST_Polygon)
INSERT INTO sample_polys
VALUES (1, ST_Polygon('polygon
((40 120, 90 120, 90 150, 40 150, 40 120),
(50 130, 60 130, 60 140, 50 140, 50 130),
(70 130, 80 130, 80 140, 70 140, 70 130))' , 0) )
INSERT INTO sample_polys
VALUES (2, ST_Polygon('polygon ((5 15, 50 15, 50 105, 5 15))' , 0) )
The ST_NumInteriorRing function is used to return
the number of rings in the geometries in the table:
SELECT id, ST_NumInteriorRing(geometry) NUM_RINGS
FROM sample_polys
Results:
ID NUM_RINGS
---------- ---------------
1 2
2 0
