This topic describes the ST_Contains function. This function checks whether the first geometry object that you specify contains the second geometry object that you specify. If the first geometry object contains the second geometry object, this function returns True. Otherwise, this function returns False.

Syntax

boolean  ST_Contains(geometry  geomA , geometry  geomB);

Parameters

Parameter Description
geomA The first geometry object that you want to specify.
geomB The second geometry object that you want to specify.

Description

  • The first geometry object that you specify contains the second geometry object that you specify only when no points of the second geometry object lie outside the first geometry object and at least one point of the second geometry object lies inside the first geometry object.
    • The ST_Contains function does not count in the boundary of the first geometry object. The ST_Contains function counts in only the first geometry object itself.
    • The ST_ContainsProperly function does not count in the first geometry object itself.
  • The two geometry objects that you specify must use the same projection method and have the same spatial reference identifier (SRID).
  • The ST_Contains function is inverse to the ST_Within function.

    The ST_Contains(A,B) function and the ST_Within(B,A) function return the same result unless you specify invalid geometry objects in one of the functions.

  • The ST_Contains function does not support GeometryCollection objects.
  • The ST_Contains function generates a bounding box, which allows you to use the indexes that are available on the geometry objects that you specify. If you do not want to use the indexes, we recommend that you use the _ST_Contains function.

Examples

SELECT ST_Contains('POLYGON((0 0,0 3,3 0,0 0))'::geometry,'POLYGON((0 0,0 1,1 0,0 0))'::geometry);
 st_contains
-------------
 t
(1 row)