Name

ST_Difference — Returns a geometry that represents the point set difference of a Geometry with another Geometry.

Synopsis

geometry ST_Difference(bytea GeomA, bytea GeomB);

Alias

Difference

Description

Returns a geometry that represents the point set difference of a Geometry with another Geometry. This method returns the closure of the resultant Geometry.

[Note]

GeometryCollections are unsupported.

Coordinate Dimensions
2D3DM
Spatial Standards Support
OGC SFS for SQL. 1.1 (1999)OGC SFS for SQL. 1.1.0 (2005)OGC SFS for SQL. 1.2.0 (2006)SQL-MM Part 3
2.1.1.37.2.21.17.2.8.15.1.20

Examples

SELECT ST_AsEWKT(ST_Difference(A,B)) from 
(SELECT ST_GeomFromText('POLYGON ((40 20, 40 100, 120 100, 120 20, 40 20))',25830) as A,
ST_GeomFromText('POLYGON ((80 60, 80 130, 170 130, 170 60, 80 60))',25830) as B) as foo;
--Result
SRID=25830;POLYGON ((40 20, 40 100, 80 100, 80 60, 120 60, 120 20, 40 20))

ST_Difference (A,B)

ST_Difference (B,A)

Related functions

ST_SymDifference