ST_WITHIN()

All functions > GEOSPATIAL > ST_WITHIN()

Returns TRUE if geometry/geography A is fully within geometry/geography B.

Signatures

Within

Returns: TRUE if A is within B

ST_WITHIN(geo1: T, geo2: T) → BOOLEAN
sql
ParameterTypeRequiredDescription
geo1TYesGeometry or geography to test
geo2TYesContainer geometry or geography

With:

  • T : Custom types: GEOM_POINT | GEOM_LINESTRING | GEOM_POLYGON | GEOM_MULTIPOINT | GEOM_MULTILINESTRING | GEOM_MULTIPOLYGON | GEOM_MULTIANY | GEOG_POINT | GEOG_LINESTRING | GEOG_POLYGON | GEOG_MULTIPOINT | GEOG_MULTILINESTRING | GEOG_MULTIPOLYGON | GEOG_MULTIANY

Signature notes:

  • ST_WITHIN(A, B) is equivalent to ST_CONTAINS(B, A)
  • Both inputs must be the same type family
  • Returns NULL if either input is NULL

Examples

Geometry

FeatureQL
SELECT
    f1 := ST_WITHIN(ST_GEOMPOINT(5.0, 5.0), ST_GEOMFROMTEXT('POLYGON ((0 0, 10 0, 10 10, 0 10, 0 0))')), -- Point within polygon
    f2 := ST_WITHIN(ST_GEOMPOINT(15.0, 15.0), ST_GEOMFROMTEXT('POLYGON ((0 0, 10 0, 10 10, 0 10, 0 0))')) -- Point outside polygon
;
Result
f1 BOOLEANf2 BOOLEAN
truefalse

Geography

FeatureQL
SELECT
    f1 := ST_WITHIN(ST_GEOGPOINT(2.33, 48.86), ST_GEOGFROMTEXT('POLYGON ((2.29 48.85, 2.36 48.85, 2.36 48.87, 2.29 48.87, 2.29 48.85))')) -- Point within Paris polygon
;
Result
f1 BOOLEAN
true

Last update at: 2026/05/26 17:22:09