As a rule, converting a polygon to a string may not be easy, because there is no unique display and different elements of the polygonal map for different lines (outer ring, inner rings, etc.).
Given this, you need to separate each of them according to the following possible approach, for example:
SELECT ST_AsText( ST_MakeLine(sp,ep) ) FROM -- extract the endpoints for every 2-point line segment for each linestring (SELECT ST_PointN(geom, generate_series(1, ST_NPoints(geom)-1)) as sp, ST_PointN(geom, generate_series(2, ST_NPoints(geom) )) as ep FROM -- extract the individual linestrings (SELECT (ST_Dump(ST_Boundary(geom))).geom FROM mypolygontable ) AS linestrings ) AS segments;
depending on what polygon data is stored in mypolygontable , you may want to reset not only the border (as described above using ST_Boundary ), but also other elements. The code above with a more detailed overview is taken from the postgis-users list: Split the polygon into N linestrings
There is also a general approach to the problem described in Line break or polygon into separate vectors in PostGIS
mloskot
source share