I have 23 tables in a PostGIS schema which I need to count the number of vertices of. The tables are a mixture of lines and polygons so realised I need to use ST_NPoints(geom)

So I ran the following query

SELECT count(ST_NPoints(geom) FROM lines;

the result/count equals the number of features in that table and not the total number of vertices of all features in that table.

I must be missing something but cannot figure it out (must be monday morning ;))

1 Answer 1


With your query you are only counting the number of rows in your table (see it, as the number of times that you are calling st_npoints), you need to sum the results that returns st_npoints for each geometry

SELECT sum(ST_NPoints(geom)) FROM lines;
  • many thanks that works perfectly. I knew it must be simple
    – tjmgis
    Commented Aug 12, 2013 at 10:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.