ST_EQUALS scalar function

The ST_EQUALS function takes two geometry objects as input parameters and returns the integer 1 if the latitude and longitude of the geometries are equal. Otherwise, the integer 0 (zero) is returned.

The order of the points used to define the geometry is not relevant for the test for equality.

If geometry1 or geometry2 is null, the result is the null value. If geometry1 or geometry2 is empty, 0 (zero) is returned. If both geometry1 and geometry2 are empty, 1 is returned.

Read syntax diagramSkip visual syntax diagramST_EQUALS(geometry1,geometry2)

Parameters

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.

The result of the function is INTEGER.

Example

Compare two polygons to determine if they are the same. Two geometries are equal if the coordinates are the same but in a different order. This is demonstrated by the first row in the following table.

CREATE TABLE sample_geometry (geometry_id INTEGER, geometry QSYS2.ST_GEOMETRY);
INSERT INTO sample_geometry VALUES
  (10, QSYS2.ST_POLYGON('polygon((50 30, 30 30, 30 50, 50 50, 50 30))')),
  (20, QSYS2.ST_POLYGON('polygon((10 20, 50 50, 30 50, 30 40, 10 20))'));
  
CREATE VARIABLE my_polygon QSYS2.ST_POLYGON;
SET my_polygon = QSYS2.ST_POLYGON('polygon((50 30, 50 50, 30 50, 30 30, 50 30))');

SELECT geometry_id, QSYS2.ST_EQUALS(geometry, my_polygon) AS equals
  FROM sample_geometry;

Results:


GEOMETRY_ID     EQUALS
-------------   -------
           10         1
           20         0