All Products
Search
Document Center

ApsaraDB RDS:ST_Within

Last Updated:Mar 28, 2026

Tests whether all points of a geometry or grid lie within a target geometry or grid.

Syntax

boolean ST_Within(geomgrid grid, geometry geom);
boolean ST_Within(geometry geom, geomgrid grid);
boolean ST_Within(geomgrid grid1, geomgrid grid2);

Parameters

ParameterDescription
gridThe geomgrid object to test.
geomThe geometry object to test.

Usage notes

The geometry argument must use the CGC2000 spatial reference system. Its spatial reference system identifier (SRID) must be 4490.

Examples

Check whether a point lies within a grid

The query returns f (false) — the point is outside the specified grid.

select st_within(
  ST_GeomFromText('POINT(116.31522216796875 39.910277777777778)', 4490),
  ST_GridFromText('G001331032213300013')
);

 st_within
---------------
 f

Check whether one grid lies within another

The query returns t (true) — G001331032213300013 is fully contained within G001331032213300.

select st_within(
  ST_GridFromText('G001331032213300013'),
  ST_GridFromText('G001331032213300')
);

 st_within
-------------
 t