I have a table full of a mix of polygons and multipolygons and I would like to run a single function on to break them into LineStrings (or MultiLinestrings).
My problem - I am currently returning a set with ... no geometry (?)...
The function currently looks like this...(final based on Mike T. help)
CREATE OR REPLACE FUNCTION LinesFromPoly2(polygon geometry) 
RETURNS SETOF geometry_dump AS 
$BODY$DECLARE 
 m integer; 
 g geometry;
 p geometry_dump%ROWTYPE; 
BEGIN
    FOR m IN SELECT generate_series(1, ST_NumGeometries($1)) LOOP 
      p.path[1] := m;
      p.geom := ST_Boundary(ST_GeometryN($1, m));
     RETURN NEXT p;
     END LOOP;
  RETURN; 
END;$BODY$
LANGUAGE plpgsql ;
CALL:
SELECT id, name, LinesFromPoly2(the_geom)
  FROM public.poly_and_multipoly;
RETURNS:
1|A|({1},)
2|B|({1},)
2|B|({2},)
SAMPLE DATA:
CREATE TABLE poly_and_multipoly (
  "id" SERIAL NOT NULL PRIMARY KEY,
  "name" char(1) NOT NULL,
  "the_geom" geometry NOT NULL
);
-- add data, A is a polygon, B is a multipolygon
INSERT INTO poly_and_multipoly (name, the_geom) VALUES (
    'A', 'POLYGON((7.7 3.8,7.7 5.8,9.0 5.8,7.7 3.8))'::geometry
    ), (
    'B',
    'MULTIPOLYGON(((0 0,4 0,4 4,0 4,0 0),(1 1,2 1,2 2,1 2,1 1)), ((-1 -1,-1 -2,-2 -2,-2 -1,-1 -1)))'::geometry
);
				
                        
You don't need a custom function to do what you want. For instance, try just accessing the two members of
ST_Dump(pathandgeom):Or one [MULTI]LINESTRING per geometry part:
But if you did want to use your
LinesFromPolygon2function, the fix is simple: assign the geometry top.geom, notg, i.e.