Categories:

Geospatial Functions

ST_WITHIN

Returns true if the first geospatial object g1 is fully contained by the second geospatial object g2. Calling ST_WITHIN(g1, g2) is equivalent to calling ST_CONTAINS(g2, g1).

See also:

ST_CONTAINS

Syntax

ST_WITHIN( <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_WITHIN 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_WITHIN(g1, g2) 
    FROM geospatial_table_01;
+-------------------+
| ST_WITHIN(G1, G2) |
|-------------------|
| False             |
+-------------------+