All Products
Search
Document Center

ApsaraDB RDS:ST_Contains

Last Updated:Mar 28, 2026

ST_Contains returns true if the first argument spatially contains the second. Containment holds when all points of the second argument lie within the interior or boundary of the first, and the two interiors share at least one point.

Syntax

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

Parameters

ParameterDescription
gridThe grid whose spatial relationship you want to query.
geomThe geometry whose spatial relationship you want to query.
grid1The geomgrid value to test as the container (grid-vs-grid overload).
grid2The geomgrid value to test as the contained object (grid-vs-grid overload).

Examples

Example 1: Grid does not contain the point

The grid G001331032213300013 is a fine-grained cell. The POINT at approximately (116.315, 39.910) falls outside it, so the function returns f.

SELECT ST_Contains(
  ST_GridFromText('G001331032213300013'),
  ST_GeomFromText('POINT(116.31522216796875 39.910277777777778)', 4490)
);
 st_contains
-------------
 f

Example 2: Parent grid contains a child grid

The shorter grid code G00133103221330 represents a coarser cell that fully contains G001331032213300013, so the function returns t.

SELECT ST_Contains(
  ST_GridFromText('G00133103221330'),
  ST_GridFromText('G001331032213300013')
);
 st_contains
-------------
 t