ST_SymDifference
What is ST_SymDifference?
ST_SymDifference returns the symmetric difference of two geometries — the parts that lie in exactly one of the inputs but not in both. It is equivalent to ST_Union(ST_Difference(a,b), ST_Difference(b,a)).
1ST_SymDifference(geometry g1, geometry g2) → geometry
2ST_SymDifference(geometry g1, geometry g2, float gridSize) → geometryThe optional gridSize (PostGIS 3.1+) snaps to a precision grid for robust overlay.
When would you use ST_SymDifference?
Use ST_SymDifference in change-detection workflows: comparing two versions of a boundary layer to highlight added and removed area, visualising the non-overlapping portions of two competing service areas, or producing "changed since last survey" patches between two cadastral datasets. Paired with ST_Area, it quantifies the magnitude of geometric change.
1-- Net changed area between two snapshots of a forest cover layer
2SELECT ST_Area(ST_SymDifference(a.geom, b.geom)::geography) AS changed_m2
3FROM forest_2020 a, forest_2025 b
4WHERE a.id = b.id;FAQs
Is it symmetric in the arguments?
Yes — ST_SymDifference(a, b) and ST_SymDifference(b, a) return the same geometry. This is the defining property relative to ST_Difference, which is asymmetric.
What does it return for identical inputs?
An empty geometry — nothing lies in exactly one of two identical inputs.
What is the relationship to Union and Intersection?
ST_SymDifference(a, b) = ST_Difference(ST_Union(a, b), ST_Intersection(a, b)). In set terms, it is (A ∪ B) \ (A ∩ B).
What about 3D?
ST_SymDifference is 2D. Z and M values are not reliably preserved across overlay. For 3D set operations use SFCGAL functions.