Fork me on GitHub

ST_Accum

Signatures

MULTIPOINT         ST_Accum(POINT geom);
MULTILINESTRING    ST_Accum(LINESTRING geom);
MULTIPOLYGON       ST_Accum(POLYGON geom);
GEOMETRYCOLLECTION ST_Accum(GEOMETRY geom);

Description

This aggregate function constructs a GEOMETRYCOLLECTION from a column of mixed dimension Geometries.

If there is only POINTs in the column of Geometries, a MULTIPOINT is returned. Same process with LINESTRINGs and POLYGONs.

Examples

Case with same dimension geometries

CREATE TABLE input_table(geom GEOMETRY);
INSERT INTO input_table VALUES
    ('POINT(0 0)'),
    ('POINT(1 1)'),
    ('POINT(2 2)');
SELECT ST_Accum(geom) FROM input_table;
-- Answer: MULTIPOINT ((0 0), (1 1), (2 2))

Case with mixed dimension geometries

CREATE TABLE input_table(geom GEOMETRY);
INSERT INTO input_table VALUES
    ('POLYGON((9 0, 9 11, 10 11, 10 0, 9 0))'),
    ('POLYGON((1 1, 1 7, 7 7, 7 1, 1 1))'),
    ('POINT(1 1)'),
    ('POINT(2 2)');
SELECT ST_Accum(geom) FROM input_table;
-- Answer: GEOMETRYCOLLECTION(
--    POLYGON((9 0, 9 11, 10 11, 10 0, 9 0)),
--    POLYGON((1 1, 1 7, 7 7, 7 1, 1 1)),
--    POINT(1 1), POINT(2 2))

See also