Skip to main content

ST_Equals

Tests whether two geometries are spatially equal (represent the same geometry).

Syntax

ST_Equals(geometry_a, geometry_b)

Parameters

ParameterTypeDescription
geometry_aGeometryFirst geometry
geometry_bGeometrySecond geometry

Returns

TypeDescription
BooleanTrue if geometries are spatially equal, false otherwise

Examples

Same Polygon, Different Order

SELECT ST_Equals(
ST_GeomFromText('POLYGON((0 0, 4 0, 4 4, 0 4, 0 0))'),
ST_GeomFromText('POLYGON((0 4, 0 0, 4 0, 4 4, 0 4))')
);
-- Returns: true (same polygon, different vertex order)

Reversed LineString

SELECT ST_Equals(
ST_GeomFromText('LINESTRING(0 0, 1 1, 2 0)'),
ST_GeomFromText('LINESTRING(2 0, 1 1, 0 0)')
);
-- Returns: true (same line, reversed direction)

Find Duplicate Geometries

SELECT a.id as id_a, b.id as id_b
FROM features a, features b
WHERE a.id < b.id
AND ST_Equals(a.geom, b.geom);

Notes

  • Spatial equality ignores vertex order and direction
  • Different from binary equality (bytes must match)
  • Two geometries are equal if they cover the same space
  • Useful for deduplication and data validation

See Also