All Products
Search
Document Center

PolarDB:ST_Intersection

Last Updated:Mar 28, 2026

Returns the geometry that represents the shared area between two geometry or geography objects.

Syntax

geometry  ST_Intersection(geometry geomA, geometry geomB);
geography ST_Intersection(geography geogA, geography geogB);
geometry  ST_Intersection(geometry set gField);

Parameters

ParameterDescription
geomA / geomBThe two geometry objects to intersect.
geogA / geogBThe two geography objects to intersect.
gFieldThe geometry field to aggregate across all rows.

Usage notes

Note

If the two input geometry objects do not intersect, the function returns an empty geometry object.

Note

For geography inputs, the function converts them to geometry objects first, computes the intersection in the planar spatial reference, and then transforms the result back to a geography object using the World Geodetic System 1984 (WGS 84) coordinate system.

Note

GeometryCollection objects are not supported.

Warning

M coordinates are dropped from the input objects.

Examples

Compute the intersection of two polygons

SELECT ST_AsText(
  ST_Intersection(
    'POLYGON((0 0,0 2,2 2,2 0,0 0))'::geometry,
    'POLYGON((0 0,3 0,3 1,0 1,0 0))'::geometry
  )
);

Result:

           st_astext
--------------------------------
 POLYGON((0 0,0 1,2 1,2 0,0 0))
(1 row)

Compute the aggregate intersection of a geometry set

The aggregate form of ST_Intersection takes a geometry field as input and intersects all geometries in the set sequentially, returning the shared area across all of them.

-- Create a table and insert sample geometries
CREATE TABLE agg_result (id integer, geom geometry);

INSERT INTO agg_result VALUES
  (0, ST_GeomFromText('POLYGON((0 0, 0 0.5, 0.5 0.5, 0.5 0, 0 0))'));

INSERT INTO agg_result
  SELECT i, st_buffer('POINT(0 0)', 0.8 + random() * 0.1)
  FROM generate_series(1, 100) AS i;

-- Compute the intersection across all rows
SELECT ST_AsText(ST_Intersection(geom)) AS intersection_result
FROM agg_result;

Result:

               st_astext
----------------------------------------
 POLYGON((0 0,0 0.5,0.5 0.5,0.5 0,0 0))
(1 row)

The small square polygon (row 0) is entirely contained within all the buffered circles (rows 1–100), so it is returned as the intersection of the entire set.

Figure 1