Converts the geometry to a multi-polygon value.
SELECT NEW ST_GeomCollection().ST_ToMultiPolygon()
The following returns an error because the Shape column is of type ST_Geometry and ST_Geometry does not support the ST_Area method.
SELECT Shape.ST_Area() FROM SpatialShapes WHERE ShapeID = 27
The following uses ST_ToMultiPolygon to change the type of the Shape column expression to ST_MultiPolygon. This example would also work with ShapeID 22, where the Shape value is of type ST_LineString. ST_Area returns the result 8.
SELECT Shape.ST_ToMultiPolygon().ST_Area() FROM SpatialShapes WHERE ShapeID = 27
In this case, the value of the Shape column is known be of type ST_MultiPolygon, so TREAT can be used to efficiently change the type of the expression. This example would notwork with ShapeID 22, where the Shape value is of type ST_Polygon. ST_Area returns the result 8.
SELECT TREAT( Shape AS ST_MultiPolygon ).ST_Area() FROM SpatialShapes WHERE ShapeID = 27
SQL/MM (ISO/IEC 13249-3: 2006) 5.1.33