This topic describes the ST_GeometryN function. This function returns the Nth object of the input geometry object.


geometry  ST_GeometryN(geometry  geomA , integer  n);


Parameter Description
geomA The geometry object that you want to specify.
n The index number of the object that you want to obtain.


  • The index number starts from 1.
  • This function supports GeometryCollection objects, MultiPoint objects, MultiLineString objects, MultiCurve objects, MultiPolygon objects, and polyhedral surfaces. If you specify another type of geometry object, this function returns NULL.
  • If you want to extract all the geometries of the input geometry object, you can use the ST_Dump function, which is more efficient and supportsvarious geometry objects.
  • This function supports circular strings, curves, polyhedral surfaces, triangles, triangulated irregular network (TIN) surfaces, and 3D objects.


  • Execute the following statement to return a MULTI object:
    SELECT ST_AsText(ST_GeometryN('MULTIPOLYGON(((1 0,3 0,0 3,1 0)),((1 0,2 0, 0 2,1 0)))'::geometry,2));
     POLYGON((1 0,2 0,0 2,1 0))
    (1 row)
  • Execute the following statement to return a GeometryCollection objects:
    SELECT ST_AsText(ST_GeometryN('GeometryCollection(POINT(1 0),POLYGON((1 0,2 0, 0 2,1 0)))'::geometry,1));
     POINT(1 0)
    (1 row)