The ST_NumInteriorRing() function

The ST_NumInteriorRing() function takes an ST_Polygon and returns the number of its interior rings.

Syntax

ST_NumInteriorRing(pl1 ST_Polygon)

Return type

INTEGER

Example

An ornithologist studying a bird population on several South Sea islands wants to identify which islands contain one or more lakes, because the bird species of interest feeds only in freshwater lakes.

The ID and name columns of the islands table identifies each island, while the land ST_Polygon column stores the island geometry:
CREATE TABLE islands (id    integer,
                      name  varchar(32),
                      land  ST_Polygon);
Because interior rings represent the lakes, the ST_NumInteriorRing() function lists only those islands that have at least one interior ring:
SELECT name
   FROM islands
   WHERE ST_NumInteriorRing(land) > 0;