All Products
Search
Document Center

ApsaraDB RDS:ST_NumGeometries

Last Updated:Mar 28, 2026

Returns the number of geometry objects in a geometry collection. For a single geometry object, returns 1. For all other input, returns NULL.

Syntax

integer ST_NumGeometries(geometry geom);

Parameters

ParameterDescription
geomThe geometry object. Supported types include geometry collections (GeometryCollection, MULTI objects), single geometry objects, polyhedral surfaces, triangles, triangulated irregular network (TIN) surfaces, and 3D objects.

Examples

Query the number of geometries in a MULTIPOLYGON:

SELECT ST_NumGeometries('MULTIPOLYGON(((1 0,0 3,3 0,1 0)),((1 0,2 0,0 2,1 0)))'::geometry);

Output:

 st_numgeometries
------------------
                2
(1 row)

Query the number of geometries in a GeometryCollection:

SELECT ST_NumGeometries('GeometryCollection(POINT(1 0),POLYGON((1 0,2 0, 0 2,1 0)))'::geometry);

Output:

 st_numgeometries
------------------
                2
(1 row)