Is it possible to import a shape file containing multipolygons into single polygon in PostGIS? Whenever I try importing a shape file of a polygon, it is stored as a multipolygon
Import into a staging table and then use ST_DUMP to brake the multigeom into individual pieces and use that to populate the destination table.
You import all the data you need into a staging table (let's call it multi
) and then use ST_DUMP
to break the mutligeometry into single geometries:
WITH multi AS(
SELECT 1 as id, 2 as test, ST_GeomFromText('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)))') as poli
)
,dump AS(
SELECT id
,test
,ST_DUMP(poli) as d
FROM multi)
SELECT id
,test
,(dump.d).path
,ST_AsTEXT((dump.d).geom)
FROM dump