ST_DumpSegments
Name
   ST_DumpSegments — Returns a set of
   
    geometry_dump
   
   rows for the segments in a geometry.
  
Synopsis
    
     geometry_dump[]
     
      ST_DumpSegments
     
     (
    
    geometry
    
     geom
    
    
     )
    
    ;
   
Description
   A set-returning function (SRF) that extracts the segments of a geometry.
            It returns a set of
   
    geometry_dump
   
   rows,
                each containing a geometry (
   
    
     geom
    
   
   field)
                and an array of integers (
   
    
     path
    
   
   field).
  
- 
     
the
geomfieldLINESTRINGs represent the segments of the supplied geometry. - 
     
the
pathfield (aninteger[]) is an index enumerating the segment start point positions in the elements of the supplied geometry. The indices are 1-based. For example, for aLINESTRINGthe paths are{i}whereiis thenthsegment start point in theLINESTRING. For aPOLYGONthe paths are{i,j}whereiis the ring number (1 is outer; inner rings follow) andjis the segment start point position in the ring. 
Availability: 3.2.0
   
    
   
   This function supports Triangles and Triangulated Irregular Network Surfaces (TIN).
  
   
    
   
   This function supports 3d and will not drop the z-index.
  
Standard Geometry Examples
SELECT path, ST_AsText(geom)
FROM (
    SELECT (ST_DumpSegments(g.geom)).*
    FROM (SELECT 'GEOMETRYCOLLECTION(
    LINESTRING(1 1, 3 3, 4 4),
    POLYGON((5 5, 6 6, 7 7, 5 5))
)'::geometry AS geom
        ) AS g
) j;
  path   │      st_astext
---------------------------------
 {1,1}   │ LINESTRING(1 1,3 3)
 {1,2}   │ LINESTRING(3 3,4 4)
 {2,1,1} │ LINESTRING(5 5,6 6)
 {2,1,2} │ LINESTRING(6 6,7 7)
 {2,1,3} │ LINESTRING(7 7,5 5)
(5 rows)
 TIN and Triangle Examples
-- Triangle --
SELECT path, ST_AsText(geom)
FROM (
    SELECT (ST_DumpSegments(g.geom)).*
    FROM (SELECT 'TRIANGLE((
        0 0,
        0 9,
        9 0,
        0 0
    ))'::geometry AS geom
        ) AS g
) j;
 path  │      st_astext
 ---------------------------------
 {1,1} │ LINESTRING(0 0,0 9)
 {1,2} │ LINESTRING(0 9,9 0)
 {1,3} │ LINESTRING(9 0,0 0)
(3 rows)
  -- TIN --
SELECT path, ST_AsEWKT(geom)
FROM (
    SELECT (ST_DumpSegments(g.geom)).*
    FROM (SELECT 'TIN(((
        0 0 0,
        0 0 1,
        0 1 0,
        0 0 0
    )), ((
        0 0 0,
        0 1 0,
        1 1 0,
        0 0 0
    ))
    )'::geometry AS geom
        ) AS g
) j;
  path   │        st_asewkt
  ---------------------------------
 {1,1,1} │ LINESTRING(0 0 0,0 0 1)
 {1,1,2} │ LINESTRING(0 0 1,0 1 0)
 {1,1,3} │ LINESTRING(0 1 0,0 0 0)
 {2,1,1} │ LINESTRING(0 0 0,0 1 0)
 {2,1,2} │ LINESTRING(0 1 0,1 1 0)
 {2,1,3} │ LINESTRING(1 1 0,0 0 0)
(6 rows)