This topic describes the ST_Different function. This function returns a geometry object representing the part that Geometry Object A does not intersect with Geometry Object B.

Syntax

geometry  ST_Difference(geometry  geomA , geometry  geomB);

Parameters

Parameter Description
geomA Geometry Object A that you want to specify.
geomB Geometry Object B that you want to specify.

Description

  • If Geometry Object A is completely contained in Geometry Object B, the ST_Different returns an empty object.
  • The order of the input geometry objects affects the output geometry object.
  • This function does not support GeometryCollection objects.
  • This function supports 3D objects and does not delete z coordinates. This function processes only the x and y coordinates of the input geometry objects but returns the output geometry object with the original z coordinates.

Examples

Results returned by using the default parameter settings:
SELECT ST_AsText(ST_Difference('LINESTRING(0 0,0 2)'::geometry,'LINESTRING(0 1,0 3)'::geometry));
      st_astext
---------------------
 LINESTRING(0 0,0 1)
(1 row)