Skip to content

ST_DIFFERENCE

Returns a GEOGRAPHY representing the part of GEOGRAPHY A that does not intersect GEOGRAPHY B. This is equivalent to A - ST_INTERSECTION(A, B).

If A is completely contained within B, an empty GEOGRAPHY of the appropriate type is returned.

See also:

Syntax

sql
ST_DIFFERENCE(<a>, <b>)

Arguments

  • <a>: The GEOGRAPHY object to subtract from
  • <b>: The GEOGRAPHY object to subtract

Returns

Returns a GEOGRAPHY representing all parts of <a> that do not intersect with <b>

Behavior

<a> subtype<b> subtypeBehavior
ST_PointST_PointReturns empty if <b> equals <a>, otherwise returns <a>
ST_PointST_LinestringReturns <a> if it is not on the line of <b>, otherwise empty
ST_PointST_PolygonReturns <a> if it does not intersect <b>, otherwise empty
ST_LinestringST_PointAlways returns <a>
ST_LinestringST_LinestringReturns an ST_GeometryCollection of parts of <a> that are not in <b>. May return a single ST_Linestring if the lines fully overlap, except in one case
ST_LinestringST_PolygonReturns an ST_GeometryCollection of all areas of <b> that do not touch the polygon in <b>
ST_PolygonST_PointAlways returns <a>
ST_PolygonST_LinestringReturns an ST_GeometryCollection containing a potentially "cut up" set of ST_polygon sliced up by the linestring in <b>. Can also return <a> if no part of <b> is inside <a>. A part of a linestring touching the polygon does not subtract from <b>
ST_PolygonST_PolygonReturns an ST_GeometryCollection slicing up <a> by the areas not in <b>. A potentially complex shape