Share via


st_union_agg function

Applies to: check marked yes Databricks Runtime 17.1 and above

Important

This feature is in Public Preview.

Returns the point-wise union of all the geometries in the column, or NULL if the column is zero rows, or contains only NULL values.

Syntax

st_union_agg ( geoCol )

Arguments

  • geoCol: A column of BINARY, GEOMETRY, or STRING values representing geometry objects.

Returns

A value of type GEOMETRY, representing the point-wise union of all geometries in the column.

The output GEOMETRY is always two-dimensional.

The function returns NULL if the column has zero rows or contains only NULL values.

Error conditions

Examples

-- Returns union of multiple geometries from column.
> SELECT st_astext(st_union_agg(st_geomfromtext(*))) FROM (SELECT * FROM VALUES('POINT(-5 -5)'),('MULTIPOINT(1 2,8 8,5 9,-7 -7,EMPTY)'),('MULTILINESTRING(EMPTY,(5 5,9 9),(9 9,15 15))'),('POLYGON((0 0,10 0,10 10,0 10,0 0))'))
  GEOMETRYCOLLECTION(MULTIPOINT((-7 -7),(-5 -5)),LINESTRING(10 10,15 15),POLYGON((0 0,10 0,10 10,0 10,0 0)))
-- Returns NULL for empty result set.
> SELECT st_union_agg(st_geomfromtext(geom)) FROM (SELECT 'POINT(1 1)' as geom WHERE false)
  NULL