ST_Within()

Returns 1 when the first geometry is completely within the second geometry.

Syntax

ST_Within(geom1, geom2)

Aliases: none.

Arguments

geom1 and geom2 are GEOMETRY values.

Return Value

Returns BOOL.

Usage Notes

  • ST_Within(a, b) is the inverse positional relationship of ST_Contains(b, a).

  • Both geometries must have the same SRID. Predicates are Cartesian (SRID 0), not geodetic SRID 4326 predicates.

Examples

DROP DATABASE IF EXISTS geo_within_demo;
CREATE DATABASE geo_within_demo;
USE geo_within_demo;

SELECT ST_Within(ST_GeomFromText('POINT(2 2)'), ST_GeomFromText('POLYGON((0 0, 4 0, 4 4, 0 4, 0 0))')) AS within_polygon;

DROP DATABASE geo_within_demo;

See Also

ST_Contains(), ST_CoveredBy().