ST_MemUnion returns a geometry object that represents the union of input geometry objects. This function is the same as the ST_Union function.
Syntax
geometry ST_MemUnion(geometry set geomfield);Parameters
| Parameter | Description |
|---|---|
geomfield | The geometry field to aggregate across the input geometry set. |
Description
ST_MemUnion produces the same result as ST_Union, but uses less memory at the cost of more processing time.
Use ST_MemUnion when memory is constrained and the slower execution time is acceptable. Use ST_Union when performance matters more than memory usage.
Examples
Union geometries by group
The following example unions the geometries in each group and returns one result geometry per group. This is the typical usage pattern for an aggregate function.
SELECT id, ST_AsText(ST_MemUnion(geom)) AS union_geom
FROM geometries
GROUP BY id;Union geometries from an inline dataset
The following example unions two polygon geometries constructed from an inline array.
SELECT ST_AsText(ST_MemUnion(g))
FROM (
SELECT unnest(ARRAY[
'POLYGON((0 0,1 0,1 2,0 2,0 0))'::geometry,
'POLYGON((1 0,3 0,3 1,1 1,1 0))'::geometry
]) AS g
) AS t;Expected output:
st_astext
--------------------------------------------
POLYGON((1 0,0 0,0 2,1 2,1 1,3 1,3 0,1 0))
(1 row)See also
ST_Union: A faster aggregate union function that uses more memory.
该文章对您有帮助吗?