- Categories:
ST_COLLECT¶
There are two forms of ST_COLLECT:
Scalar: This function combines two GEOGRAPHY objects into one.
Aggregate: This function combines all the GEOGRAPHY objects in a column into one GEOGRAPHY object.
Syntax¶
Arguments¶
geography_expression_1A GEOGRAPHY object.
geography_expression_2A GEOGRAPHY object.
Returns¶
The function returns a value of type GEOGRAPHY.
Usage notes¶
If g1 and g2 are both Point objects, the result is a MultiPoint object containing the two Points. Similarly, if g1 and g2 are both LineString objects, the result is a MultiLineString object. Etc.
If g1 and g2 are different types of geospatial objects, or if at least one of the input GEOGRAPHY objects is a collection (e.g. MultiLineString, GeometryCollection, or FeatureCollection), then the result is a GeometryCollection containing both input objects.
Examples¶
The queries below show both scalar and aggregate uses of the ST_COLLECT function.
Create and load the table:
This calls ST_COLLECT as a scalar function to create a MultiPoint value that contains both points in the same row:
This calls ST_COLLECT as an aggregate function to create a MultiPoint value that contains all the points in the same column:
This calls ST_COLLECT first as an aggregate function on each column to create MultiPoint values that contains all the points in each column, and then calls ST_COLLECT on those two MultiPoint values to create a GeometryCollection that contains all the points in both columns. The resulting GeometryCollection is hierarchical.