The ST_Equals function takes two geometries
as input parameters and returns 1 if the latitude and longitude of the
geometries are equal. Otherwise
0 (zero) is returned. The order of the points used to define the geometry
is not relevant for the test for equality, nor is the z-value or measure.

If the second geometry is not represented in the same
spatial reference system as the first geometry, it will be converted
to the other spatial reference system.

If any of the two specified
geometries is null, then null is returned.

Syntax

Parameter

geometry1

A value of type ST_Geometry that represents the geometry that
is to be compared with geometry2.

geometry2

A value of type ST_Geometry that represents the geometry that
is to be compared with geometry1.

Return type

INTEGER

Examples

Example 1

This example creates two polygons that have their coordinates
in a different order. ST_Equal is used to show that these polygons
are considered equal.

CREATE TABLE sample_geoms (id INTEGER, geometry ST_Geometry)
INSERT INTO sample_geoms VALUES
(1, ST_Geometry('polygon((50 30, 30 30, 30 50, 50 50, 50 30))' ,0))
INSERT INTO sample_geoms VALUES
(2, ST_Geometry('polygon((50 30, 50 50, 30 50, 30 30, 50 30))' ,0))
SELECT a.id, b.id, ST_Equals(a.geometry, b.geometry) Equals
FROM sample_geoms a, sample_geoms b
WHERE a.id = 1 and b.id = 2

Results:

ID ID EQUALS
----------- ----------- -----------
1 2 1

Example 2

In this example, two geometries are created with the same X
and Y coordinates, but different M coordinates (measures). When the
geometries are compared with the ST_Equal function, a 1 is
returned to indicate that these geometries have the same latitude
and longitude values.

CREATE TABLE sample_geoms (id INTEGER, geometry ST_Geometry)
INSERT INTO sample_geoms VALUES
(3, ST_Geometry('multipoint m(80 80 6, 90 90 7)' ,0))
INSERT INTO sample_geoms VALUES
(4, ST_Geometry('multipoint m(80 80 6, 90 90 4)' ,0))
SELECT a.id, b.id, ST_Equals(a.geometry, b.geometry) Equals
FROM sample_geoms a, sample_geoms b
WHERE a.id = 3 and b.id = 4

Results:

ID ID EQUALS
----------- ----------- -----------
3 4 1

Example 3

In this example, two geometries are created with a different
set of coordinates, but both represent the same geometry. ST_Equal
compares the geometries and indicates that both geometries are indeed
equal.

CREATE TABLE sample_geoms ( id INTEGER, geometry ST_Geometry )
INSERT INTO sample_geoms VALUES
(5, ST_LineString('linestring ( 10 10, 40 40 )', 0)),
(6, ST_LineString('linestring ( 10 10, 20 20, 40 40)', 0))
SELECT a.id, b.id, ST_Equals(a.geometry, b.geometry) Equals
FROM sample_geoms a, sample_geoms b
WHERE a.id = 5 AND b.id = 6

Results:

ID ID EQUALS
----------- ----------- -----------
5 6 1