ST_Collect¶
Introduction: Collects spatial values without dissolving their boundaries. Homogeneous
Point, LineString, or Polygon values produce the corresponding multi-object; mixed types
produce a GeometryCollection.
Format:
ST_Collect(geom1: Geometry, geom2: Geometry)
ST_Collect(geom: ARRAY[Geometry])
ST_Collect(geog1: Geography, geog2: Geography)
ST_Collect(geog: ARRAY[Geography])
Return type: Geometry or Geography, matching the input type
Since: v1.5.0 (Geometry), v1.9.1 (Geography)
Member order and duplicates are retained. The Geography overloads ignore null elements and use
the first non-null input's SRID for the result.
Geometry example:
SELECT ST_Collect(
ST_GeomFromText('POINT(21.427834 52.042576573)'),
ST_GeomFromText('POINT(45.342524 56.342354355)')
) AS geom
Result:
+---------------------------------------------------------------+
|geom |
+---------------------------------------------------------------+
|MULTIPOINT ((21.427834 52.042576573), (45.342524 56.342354355))|
+---------------------------------------------------------------+
Geography array example:
SELECT ST_AsEWKT(
ST_Collect(
ARRAY[
ST_GeogFromWKT('POINT(-122.4 37.8)', 4326),
ST_GeogFromWKT('POINT(-122.5 37.7)', 4326)
]
)
) AS geog
Result:
SRID=4326;MULTIPOINT ((-122.4 37.8), (-122.5 37.7))