ST_SYMDIFFERENCE()

All functions > GEOSPATIAL > ST_SYMDIFFERENCE()

Returns the geometry 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
sql
ParameterTypeRequiredDescription
geo1TYesFirst geometry
geo2TYesSecond geometry

With:

  • T : Custom types: GEOM_POINT | GEOM_LINESTRING | GEOM_POLYGON | GEOM_MULTIPOINT | GEOM_MULTILINESTRING | GEOM_MULTIPOLYGON | GEOM_MULTIANY

Signature notes:

  • The vertex layout of the result (start vertex, ring orientation, order of parts) is engine-defined: compare two results with ST_EQUALS, not their WKT
  • GEOMETRY only: GEOGRAPHY has no spherical form here; convert with ST_TOGEOMETRY for a planar answer
  • 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

Availability

StatusBackends
Availableduckdb, postgres, trino, databricks, serving

Examples

FeatureQL
RETURN
    -- Non-overlapping parts of two partially overlapping squares
    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))')
        )
    )
;
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)))