You do not need a custom function to do what you want. For example, just try to get access to two elements ST_Dump( pathand geom):
SELECT id, name,
(ST_Dump(ST_Boundary(the_geom))).path[1],
ST_AsText((ST_Dump(ST_Boundary(the_geom))).geom)
FROM poly_and_multipoly;
id | name | path | st_astext
----+------+------+-------------------------------------------
1 | A | | LINESTRING(7.7 3.8,7.7 5.8,9 5.8,7.7 3.8)
2 | B | 1 | LINESTRING(0 0,4 0,4 4,0 4,0 0)
2 | B | 2 | LINESTRING(1 1,2 1,2 2,1 2,1 1)
2 | B | 3 | LINESTRING(-1 -1,-1 -2,-2 -2,-2 -1,-1 -1)
(4 rows)
Or one [MULTI] LINESTRING for each geometric part:
SELECT id, name,
(ST_Dump(the_geom)).path[1],
ST_AsText(ST_Boundary((ST_Dump(the_geom)).geom))
FROM poly_and_multipoly;
id | name | path | st_astext
----+------+------+--------------------------------------------------------------
1 | A | | LINESTRING(7.7 3.8,7.7 5.8,9 5.8,7.7 3.8)
2 | B | 1 | MULTILINESTRING((0 0,4 0,4 4,0 4,0 0),(1 1,2 1,2 2,1 2,1 1))
2 | B | 2 | LINESTRING(-1 -1,-1 -2,-2 -2,-2 -1,-1 -1)
(3 rows)
LinesFromPolygon2, : p.geom, g, i.e.
p.geom := ST_Boundary(ST_GeometryN($1, m));