ST_MPolyFromText
What is ST_MPolyFromText?
ST_MPolyFromText parses a MULTIPOLYGON WKT string and returns the corresponding geometry. Other geometry types raise an error.
1ST_MPolyFromText(text WKT) → geometry
2ST_MPolyFromText(text WKT, integer srid) → geometryWhen would you use ST_MPolyFromText?
Use ST_MPolyFromText in ingestion pipelines for multi-part polygons — countries with islands, utility service areas with detached zones, land-use polygons with fragmented regions. The strict type check catches malformed rows at parse time.
For polymorphic inputs, prefer ST_GeomFromText and conditionally apply ST_Multi.
FAQs
What if the WKT is a plain Polygon?
An error. Use ST_Multi(ST_PolygonFromText(...)) to promote a single polygon to a multi.
Does it validate the polygons?
Only for well-formedness (ring closure, right number of coordinates). Topological validity (no self-intersections) requires ST_IsValid.
Is SRID required?
No — defaults to 0. Supply as the second argument for real-world data.
How does it relate to ST_GeomFromText?
ST_MPolyFromText is stricter — it rejects non-MultiPolygon inputs. ST_GeomFromText accepts any WKT.