The ST_MultiSurfaceAggr aggregate function can be used to combine a group of surfaces into a single collection. All of the
geometries to be combined must have both the same SRID and the same coordinate dimension.
Rows where the argument is NULL are not included.
Returns NULL for an empty group or a group containing no non-NULL values.
The resulting ST_MultiSurface has the same coordinate dimension as each surfaces.
The optional ORDER BY clause can be used to arrange the elements in a particular order so that ST_GeometryN returns them
in the desired order. If this ordering is not relevant, it is more efficient to not specify an ordering. In that case, the
ordering of elements depends on the access plan selected by the query optimizer.
ST_MultiSurfaceAggr is more efficient than ST_UnionAggr, but ST_MultiSurfaceAggr can return a collection with duplicate or
overlapping surfaces if they exist in the group of surfaces. In particular, returned collections containing overlapping surfaces
may case unexpected results if they are used as input to other spatial methods. ST_UnionAggr handles duplicate and overlapping
The following example returns a single value which combines all geometries of type ST_Surface from the SpatialShapes table
into a single collection of type ST_MultiSurface. If the Shape column was of type ST_Surface then the TREAT function and WHERE
clause would not be necessary.
SELECT ST_MultiSurface::ST_MultiSurfaceAggr( TREAT( Shape AS ST_Surface ) )
FROM SpatialShapes WHERE Shape IS OF( ST_Surface )