ST_Equals
Returns true if two geometry objects are spatially equal, false otherwise.
Two geometry objects are spatially equal when they occupy the same set of points in space — that is, when both ST_Within(A, B) and ST_Within(B, A) return true. Vertex order does not affect the result: a geometry with its points in reverse order still equals the original.
Syntax
boolean ST_Equals(geometry a, geometry b);Parameters
| Parameter | Description |
|---|---|
a | The first geometry object. |
b | The second geometry object. |
Usage notes
If either geometry object is invalid,
ST_Equalsreturnsfalseunless the two objects are binarily equal.ST_Equalsdoes not support GeometryCollection objects.To check whether two geometry objects are equal and have their coordinates in the same order, use ST_OrderingEquals.
Examples
Spatially equal geometries with reversed vertex order
LINESTRING(0 1, 2 3) and LINESTRING(2 3, 0 1) trace the same line segment in opposite directions. ST_Equals returns true because they occupy the same point set.
SELECT ST_Equals('LINESTRING(0 1,2 3)'::geometry,'LINESTRING(2 3,0 1)'::geometry);
st_equals
-----------
t
(1 row)Spatially equal geometries with an extra intermediate point
LINESTRING(0 1, 0 3) and LINESTRING(0 1, 0 2, 0 3) cover the same collinear path. The intermediate point (0 2) does not change the spatial extent, so ST_Equals returns true.
SELECT ST_Equals('LINESTRING(0 1,0 3)'::geometry,'LINESTRING(0 1,0 2,0 3)'::geometry);
st_equals
-----------
t
(1 row)