The ST_NumPoints() function

The ST_NumPoints() function returns the number of points in an ST_Geometry.

Syntax

ST_NumPoints(g1 ST_Geometry)

Return type

INTEGER

Example

The numpoints_test table has two columns: geotype, a VARCHAR column that contains a description of the type of geometry; and gl, an ST_Geometry type that contains the geometry itself:
CREATE TABLE numpoints_test (geotype varchar(12),
                             g1      ST_Geometry);
The following INSERT statements insert a point, a linestring, and a polygon:
INSERT INTO numpoints_test VALUES(
   'point',
   ST_PointFromText('point (10.02 20.01)',1000)
);

INSERT INTO numpoints_test VALUES(
   'linestring',
   ST_LineFromText('linestring (10.02 20.01, 23.73 21.92)',1000)
);

INSERT INTO numpoints_test VALUES(
   'polygon',
   ST_PolyFromText('polygon ((10.02 20.01, 23.73 21.92, 24.51
12.98,  11.64 13.42, 10.02 20.01))',1000)
);
The query lists the geometry type and the number of points in each:
SELECT geotype, ST_NumPoints(g1) Number_of_points
   FROM numpoints_test;

geotype      number_of_points 

point                       1
linestring                  2
polygon                     5