Skip to main content
Given a set of shapes (e.g., from a ), ST_Union combines that set of shapes into a single shape. The resulting shape can then be passed to functions that operate on a single shape, such as . ST_Union works on the following data types:
The non-aggregate version of ST_Union is not yet implemented.
Unlike ST_Collect, which does not change the shapes it operates on and merely gathers them into a collection, ST_Union modifies the shapes it operates on, merging them together.

Examples

In this example, we will generate a single geometry from many individual points using ST_Union.
  1. Create a temporary table to hold all the points, which will be in format:
  2. Insert the points with the following statement:
  3. Run the query below, which gathers the points into a single geometry using ST_Union, and converts the geometry to so that we can view it with geojson.io:
  4. Paste the JSON emitted in the previous step into geojson.io and you should see an image like the following, which shows the location of most of the independent bookstores in New York State: ST_Union example
  5. Finally, drop the temporary table if you no longer need it:

See also