PostGISGeometry Input

ST_GeomCollFromText

What is ST_GeomCollFromText?

ST_GeomCollFromText parses a GEOMETRYCOLLECTION WKT string and returns the corresponding geometry. It raises an error if the WKT is not a GeometryCollection.

SQL
1ST_GeomCollFromText(text WKT)geometry
2ST_GeomCollFromText(text WKT, integer srid)geometry

Passing an SRID tags the output accordingly; otherwise the SRID is 0.

When would you use ST_GeomCollFromText?

Use ST_GeomCollFromText to strict-parse a GeometryCollection, asserting that the input WKT is actually a collection. Using it in place of the more permissive ST_GeomFromText provides an early error when a schema changes unexpectedly.

It is the OGC-spec-compliant constructor for GeometryCollection values, favoured in migration scripts that audit text inputs.

FAQs

Can I pass any WKT to ST_GeomCollFromText?

No — only a GEOMETRYCOLLECTION WKT. Other geometry types raise a parse error.

Why not just use ST_GeomFromText?

ST_GeomFromText accepts any WKT. The typed constructors like ST_GeomCollFromText give better error reporting and document intent.

Does it validate members?

Only for well-formedness. Use ST_IsValid for topological validity.

Is SRID required?

No — without the second argument the SRID is 0. Tag later with ST_SetSRID if needed.