The ST_CONTAINS function determines whether value1 contains value2.
Syntax
BOOLEAN ST_CONTAINS(GEOGRAPHY <value1>, GEOGRAPHY <value2>)Parameters
value1, value2: Required. Values of the GEOGRAPHY data type. You can construct GEOGRAPHY objects by using functions such as ST_GEOGPOINT, ST_GEOGFROMWKB, ST_GEOGFROMTEXT, ST_MAKELINE, and ST_MAKEPOLYGON.
Return value
Returns a BOOLEAN value:
Returns TRUE if every point in value2 is within value1. Otherwise, returns FALSE.
Returns FALSE if value1 or value2 is an empty geography object.
A geography object does not contain its boundary.
Examples
The following examples test if the polygon POLYGON((0 0, 10 0, 10 10, 0 10, 0 0)) contains three points: one outside the polygon (20, 20), one on its boundary (0, 0), and one inside it (5, 5).
-- Returns TRUE because POINT(5 5) is inside the polygon.
SELECT ST_CONTAINS(ST_GEOGFROMTEXT('POLYGON((0 0, 10 0, 10 10, 0 10, 0 0))'), ST_GEOGFROMTEXT('POINT(5 5)'));
-- Returns FALSE because POINT(20 20) is outside the polygon.
SELECT ST_CONTAINS(ST_GEOGFROMTEXT('POLYGON((0 0, 10 0, 10 10, 0 10, 0 0))'), ST_GEOGFROMTEXT('POINT(20 20)'));
-- Returns FALSE because POINT(0 0) is on the boundary of the polygon.
SELECT ST_CONTAINS(ST_GEOGFROMTEXT('POLYGON((0 0, 10 0, 10 10, 0 10, 0 0))'), ST_GEOGFROMTEXT('POINT(0 0)'));