Categories:

Geospatial Functions

ST_CONTAINS

Intuitively, this function returns TRUE if the second geospatial object is completely inside the first geospatial 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, see:

See also:

ST_WITHIN , ST_COVERS , ST_COVEREDBY

Syntax

ST_CONTAINS( <geography_expression_1> , <geography_expression_2> )

Arguments

geography_expression_1

A GEOGRAPHY object.

geography_expression_2

A GEOGRAPHY object.

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                |
+---------------------+