# ST_Difference function

The ST_Difference function takes two geometries as input parameters and returns the part of the first geometry that does not intersect with the second geometry.

Both geometries must be of the same dimension. If either geometry is null, null is returned. If the first geometry is empty, an empty geometry of type ST_Point is returned. If the second geometry is empty, then the first geometry is returned unchanged.

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

This function can also be called as a method.

## Syntax

## Parameter

- geometry1
- A value of type ST_Geometry that represents the first geometry
to use to compute the difference to
*geometry2*. - geometry2
- A value of type ST_Geometry that represents the second geometry
that is used to compute the difference to
*geometry1*.

## Return type

db2gse.ST_Geometry

The dimension of the returned geometry is the same as that of the input geometries.

## Examples

In the following example, the results have been reformatted for readability. The spacing in your results will vary according to your display.

```
SET CURRENT FUNCTION PATH = CURRENT FUNCTION PATH, db2gse
CREATE TABLE sample_geoms (id INTEGER, geometry ST_Geometry)
INSERT INTO sample_geoms VALUES
(1, ST_Geometry('polygon((10 10, 10 20, 20 20, 20 10, 10 10))' ,0))
INSERT INTO sample_geoms VALUES
(2, ST_Geometry('polygon((30 30, 30 50, 50 50, 50 30, 30 30))' ,0))
INSERT INTO sample_geoms VALUES
(3, ST_Geometry('polygon((40 40, 40 60, 60 60, 60 40, 40 40))' ,0))
INSERT INTO sample_geoms VALUES
(4, ST_Geometry('linestring(70 70, 80 80)' ,0))
INSERT INTO sample_geoms VALUES
(5, ST_Geometry('linestring(75 75, 90 90)' ,0))
```