ST_NumLineStrings function

The ST_NumLineStrings function takes a multilinestring as an input parameter and returns the number of linestrings that it contains.

If the specified multilinestring is null or is empty, then null is returned.

Syntax

Read syntax diagramSkip visual syntax diagramST_NumLineStrings(multilinestring)

Parameter

multilinestring
A value of type ST_MultiLineString that represents the multilinestring for which the number of linestrings is returned.

Return type

INTEGER

Example

Multilinestrings are stored in the SAMPLE_MLINES table. The ST_NumLineStrings function determines how many individual geometries are within each multilinestring.

CREATE TABLE sample_mlines (id INTEGER, geometry ST_MultiLineString)

INSERT INTO sample_mlines
  VALUES (110, ST_MultiLineString ('multilinestring 
       ( (33 2, 34 3, 35 6),
         (28 4, 29 5, 31 8, 43 12),
         (39 3, 37 4, 36 7))', 1) )
INSERT INTO sample_mlines
  VALUES (111, ST_MultiLineString ('multilinestring 
       ( (3 2, 4 3, 5 6),
         (8 4, 9 5, 3 8, 4 12))', 1) )

SELECT id, ST_NumLineStrings (geometry) NUM_WITHIN
  FROM sample_mlines
Results:

ID          NUM_WITHIN
----------- ----------
        110          3
        111          2