ST_Different

更新时间:
复制 MD 格式

Returns the part of geometry A that does not intersect with geometry B.

Syntax

geometry ST_Difference(geometry geomA, geometry geomB);

Parameters

ParameterDescription
geomAThe first geometry object.
geomBThe second geometry object.

Usage notes

  • If geomA is completely contained within geomB, the function returns an empty geometry.

  • The order of the input geometry objects affects the output. ST_Difference(A, B) and ST_Difference(B, A) produce different results.

  • GeometryCollection objects are not supported.

  • For 3D geometries, the function processes only the X and Y coordinates but preserves the original Z coordinates in the output.

Example

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)