All Products
Search
Document Center

PolarDB:ST_CostUnion

Last Updated:Mar 28, 2026

Merges multiple gridcost arrays into a single unified array.

Syntax

gridcost[] ST_CostUnion(gridcost[] barriers);

Parameters

ParameterDescription
barriersThe cost arrays of grids to merge.

Description

ST_CostUnion combines all input gridcost arrays into one array using the following rules:

  • Overlapping grids: Retains only the highest cost value. Each overlapping grid appears once in the result.

  • Degenerate grids: Merges the cost arrays of degenerate grids into the unified array.

Example

The following example merges two cost arrays. Grid GZ01 has a cost of 1, and grid GZ0 has a cost of 5. After the merge, the overlapping grid retains the higher cost value of 5.

SELECT ST_CostUnion(
  ARRAY[
    ST_SetCost(ARRAY[ST_GridFromText('GZ01')], 1),
    ST_SetCost(ARRAY[ST_GridFromText('GZ0')],  5)
  ]
);

Output:

{"({0102400100000000},5)"}