ST_SYMDIFFERENCE()
All functions > GEOSPATIAL > ST_SYMDIFFERENCE()
Returns the geometry/geography representing the point set symmetric difference of two inputs (union minus intersection).
Signatures
Symmetric difference
Returns: Parts of A and B that do not overlap; sub kind depends on result shape
ST_SYMDIFFERENCE(geo1: T, geo2: T) → GEOMETRY or GEOGRAPHY sql
| Parameter | Type | Required | Description |
|---|---|---|---|
geo1 | T | Yes | First geometry or geography |
geo2 | T | Yes | Second geometry or geography |
With:
T: Custom types: GEOM_POINT | GEOM_LINESTRING | GEOM_POLYGON | GEOM_MULTIPOINT | GEOM_MULTILINESTRING | GEOM_MULTIPOLYGON | GEOM_MULTIANY | GEOG_POINT | GEOG_LINESTRING | GEOG_POLYGON | GEOG_MULTIPOINT | GEOG_MULTILINESTRING | GEOG_MULTIPOLYGON | GEOG_MULTIANY
Signature notes:
- Equivalent to ST_UNION(A, B) minus ST_INTERSECTION(A, B), or ST_UNION(ST_DIFFERENCE(A, B), ST_DIFFERENCE(B, A))
- Two disjoint geometries: returns their union
- Two identical geometries: returns an empty geometry
- Both inputs must be the same type family
- Returns NULL if either input is NULL
Examples
FeatureQL
SELECT
f1 := ST_ASTEXT(ST_SYMDIFFERENCE(ST_GEOMFROMTEXT('POLYGON ((0 0, 3 0, 3 3, 0 3, 0 0))'), ST_GEOMFROMTEXT('POLYGON ((2 2, 5 2, 5 5, 2 5, 2 2))'))) -- Non-overlapping parts of two partially overlapping squares (DuckDB: ST_Union of mutual ST_Difference; WKT ring order may differ from other engines)
;Result
| f1 VARCHAR |
|---|
| MULTIPOLYGON (((0 0, 0 3, 2 3, 2 2, 3 2, 3 0, 0 0)), ((5 5, 5 2, 3 2, 3 3, 2 3, 2 5, 5 5))) |
On this page