PostGISGeometry Editors

ST_ForceCollection

What is ST_ForceCollection?

ST_ForceCollection returns a GEOMETRYCOLLECTION containing the input geometry. A bare POINT becomes GEOMETRYCOLLECTION(POINT(...)), and an existing collection is returned unchanged (though re-emitted as a new value).

SQL
ST_ForceCollection(geometry geom)geometry

The output SRID and vertex data match the input.

When would you use ST_ForceCollection?

Use ST_ForceCollection when a downstream consumer — some GIS engines, serialization formats, or reporting systems — expects every record to be a collection regardless of component count. Forcing a collection avoids type checks and keeps schemas uniform.

It is also useful in CTEs that mix geometry types but feed into a single column: wrapping each row with ST_ForceCollection guarantees a compatible type before further aggregation.

FAQs

Does ST_ForceCollection flatten nested collections?

No. A GeometryCollection passed in is returned as-is. Use ST_CollectionHomogenize to flatten nesting.

How is this different from ST_Multi?

ST_Multi produces a typed MULTI* (MultiPoint, MultiLineString, MultiPolygon), preserving the underlying feature class. ST_ForceCollection always produces a heterogeneous GEOMETRYCOLLECTION, which may be rejected by typed columns such as geometry(MultiPolygon, 4326).

Can I revert with ST_CollectionExtract?

Yes, provided only one geometry type is present. ST_CollectionExtract(geom, 3) pulls polygonal members out and returns a MULTIPOLYGON.

Does ST_ForceCollection change SRID or coordinates?

No. It only changes the outer type wrapper.