Categories:

Geospatial Functions

ST_CONTAINS

Intuitively, this function returns TRUE if the second GEOGRAPHY object is completely inside the first GEOGRAPHY object.

More strictly, object g1 contains object g2 if and only if no points of g2 lie in the exterior of g1, and at least one point of the interior of B lies in the interior of A. There are certain subtleties in this definition that are not immediately obvious. For more details on what “contains” means, see the Dimensionally Extended 9-Intersection Model (DE-9IM).

Note

This function does not support using a GeometryCollection or FeatureCollection as input values.

See also:

ST_WITHIN , ST_COVERS , ST_COVEREDBY

Syntax

ST_CONTAINS( <geography_expression_1> , <geography_expression_2> )

Arguments

geography_expression_1

A GEOGRAPHY object that is not a GeometryCollection or FeatureCollection.

geography_expression_2

A GEOGRAPHY object that is not a GeometryCollection or FeatureCollection.

Returns

BOOLEAN.

Examples

This shows a simple use of the ST_CONTAINS function:

create table geospatial_table_01 (g1 GEOGRAPHY, g2 GEOGRAPHY);
insert into geospatial_table_01 (g1, g2) values 
    ('POLYGON((0 0, 3 0, 3 3, 0 3, 0 0))', 'POLYGON((1 1, 2 1, 2 2, 1 2, 1 1))');
SELECT ST_CONTAINS(g1, g2) 
    FROM geospatial_table_01;
+---------------------+
| ST_CONTAINS(G1, G2) |
|---------------------|
| True                |
+---------------------+