Skip to main content
spatial relationship functions use arguments to test for different types of spatial relationships.

ST_CLUSTERDBSCAN

Returns the cluster number for each input geography based on a two-dimensional implementation of the density-based spatial clustering of applications with noise (DBSCAN) algorithm. This function is a window function because the resulting value for an individual row depends on other rows and not just itself. No frame specification is allowed. This function supports sort orders, but it is unnecessary unless deterministic resolution of tie-breaking in cluster determination is required. This tie-breaking happens only in situations where a point on the boundary of a cluster is equally valid for multiple clusters. In these cases, the result depends on the sort order of the data. For this reason, you might want to sort the data to force the deterministic behavior by using an ORDER BY in the OVER clause. The function returns NULL for any row not included in a cluster. Syntax
SQL
Example
SQL
Output: 1

ST_CONTAINS

Returns TRUE if the first geographic argument, geo1, contains the second geographic argument, geo2. geo1 contains geo2 only if all of these criteria are met:
  • No POINT values of geo2 are located at the exterior of geo1.
  • At least one POINT in the interior of geo2 lies in the interior of geo1.
Geographies do not contain their boundaries, therefore, all POINT values in a LINESTRING are interior, except for the endpoints, which are regarded as exterior boundaries. If either geo1 or geo2 is NULL, then the function returns NULL. Syntax
SQL
Example
SQL
Output: true

ST_CONTAINSPROPERLY

This function is similar to ST_CONTAINS, but it has stricter criteria. Returns true if geo2 lies entirely in the interior of geo1 and does not intersect or touch the boundary or exterior points. Returns NULL if either geo1 or geo2 is NULL. Syntax
SQL
Examples In this example, the first geographic object is a POLYGON representing a simple square (0 0, 1 0, 1 1, 0 1). The second geographic object is a small LINESTRING that spans from the point (0.25 0.25) to the point (0.75 0.75). Because the line is located entirely within the polygon, never touching its boundaries, the function evaluates to true.
SQL
Output: TRUE The second geographic object is slightly altered in this example, where the line spans from (0 0) to (1 1). Both of these endpoints touch the boundaries of the polygon, so the function now evaluates to false.
SQL
Output: FALSE

ST_COVERS

Returns TRUE if no POINT in geo2 is outside of geo1. Returns NULL if either geo1 or geo2 is NULL. Syntax
SQL
Example
SQL
Output: TRUE

ST_COVEREDBY

This function operates similarly to ST_COVERS, except the arguments are interchanged. Returns TRUE if no POINT in geo1 is outside of geo2. Returns NULL if either geo1 or geo2 is NULL. Syntax
SQL
Example
SQL
Output: TRUE

ST_CROSSES

Returns TRUE if two geospatial objects meet this criteria:
  • The intersection of the geospatial interiors is not empty.
  • The intersection is not equal to geo1 or geo2.
  • Neither geospatial object is a single POINT.
Returns NULL if either argument is NULL. Syntax
SQL
Example
SQL
Output: TRUE

ST_DISJOINT

Returns true if the specified geographies have no intersection, including boundaries. Both geographic arguments can be different types. This function is the opposite of the ST_INTERSECTS function. Syntax
SQL
Example
SQL
Output: TRUE

ST_DWITHIN

Returns TRUE if the geographies are within a specified distance in meters. Syntax
SQL
Example
SQL
Output: FALSE

ST_EQUALS

Returns TRUE if both geographies are spatially equal. Syntax
SQL
Example
SQL
Output: True

ST_INTERSECTS

Returns TRUE if the specified geographies intersect, including boundaries. This function is the opposite of the ST_DISJOINT function. Syntax
SQL
Example
SQL
Output: FALSE

ST_ISCCW

Alias for ST_ISPOLYGONCCW.

ST_ISCLOSED

Returns TRUE if an input LINESTRING has starting and ending points that are equal. If you specify a POLYGON or POINT value, the function returns true if the specified geography is not empty. Syntax
SQL
Example
SQL
Output: TRUE

ST_ISPOLYGONCW

Alias for BOOLNOT(ST_ISCCW(poly)). Returns TRUE if an input POLYGON has an exterior that is clockwise. If the POLYGON argument is empty, this function returns TRUE. If the argument is NULL, this function returns NULL. Syntax
SQL
Example
SQL
Output: FALSE

ST_ISPOLYGONCCW

Alias for ST_ISCCW. Returns TRUE if an input POLYGON has an exterior that is counter-clockwise. If the POLYGON argument is empty, this function returns TRUE. If the argument is NULL, this function returns NULL. Syntax
SQL
Example
SQL
Output: TRUE

ST_ISRING

Returns TRUE if the specified LINESTRING is closed and does not intersect itself. This function is equivalent to evaluating both ST_ISCLOSED and ST_ISSIMPLE. If you specify a value other than LINESTRING, the function throws an error. Syntax
SQL
Example
SQL
Output: TRUE

ST_ISSIMPLE

For LINESTRING values, this function returns FALSE if any line segments intersect anywhere besides the endpoints. For POLYGON values, the function returns FALSE if either the exterior ring or any interior hole is not simple. For POINT values, the function always returns TRUE. Syntax
SQL
Example
SQL
Output: TRUE

ST_ISVALID

Returns TRUE if the specified geospatial value is a well-formed and valid geography according to the OGC standards. LINESTRING values are not valid if they are composed of more than one POINT with the same coordinates. POLYGON values are valid if they are composed of one external ring (shell) and zero or more internal rings. A ring is a LINESTRING where only the first and last POINT intersect each other. All internal rings need to be contained inside the shell, and none of the rings should intersect with each other in more than one POINT. Syntax
SQL
Example
SQL
Output: TRUE

ST_OVERLAPS

Returns TRUE if both geographic arguments are of the same dimension and intersect, but neither contains the other. Returns NULL if either geo1 or geo2 is NULL. Syntax
SQL
Example
SQL
Output: TRUE

ST_POINTINSIDECIRCLE

Returns TRUE if the geographic object is inside a circle centered at the specified point coordinates and with the specified radius. Syntax
SQL
Example
SQL
Output: TRUE

ST_RELATE

Returns the DE-9IM intersection string that represents the nature of the intersection with the specified geographies. If you specify an intersection pattern as the third argument, this function returns TRUE if the intersection of the geographies satisfies the pattern and FALSE otherwise. Syntax
SQL
Examples Determine the nature of the intersection between the point (0.0, 0.0) and the line from -1 0 to 1 0. This function returns the DE-9IM string 0FFFFF102, which means that the boundaries do not intersect at all, but there is evidence of an intersection at the zero, one, and two-dimensional spaces.
SQL
*Output: *0FFFFF102 Determine whether the intersection between the point (0.0, 0.0) and the line from -1 0 to 1 0 follows the DE-9IM pattern string TF*FFF102. This function returns TRUE, which means the nature of the intersection between these two geographies conforms to this pattern.
SQL
*Output: *TRUE

ST_TOUCHES

Returns TRUE if the only POINT values in common between the two geographic arguments lie in the union of their boundaries. Syntax
SQL
Example
SQL
Output: TRUE

ST_WITHIN

Returns TRUE if the geography specified by the first argument is fully inside the geography specified by the second argument. ST_WITHIN(geo1, geo2) is equivalent to ST_CONTAINS(geo2, geo1). For details, see ST_CONTAINS. Syntax
SQL
Example
SQL
Output: true Geospatial Data Types Spatial Measurement Spatial Operators
Last modified on May 20, 2026