---
title: st_nrings function
description: Learn the syntax of the st\_nrings function of the SQL language in Databricks SQL and Databricks Runtime.
canonical_url: https://docs.databricks.com/gcp/en/sql/language-manual/functions/st_nrings
---

# `st_nrings` function

**Applies to:** ![check marked yes](https://docs.databricks.com/gcp/en/images/icons/check.png) Databricks SQL ![check marked yes](https://docs.databricks.com/gcp/en/images/icons/check.png) Databricks Runtime 18.1 and above ![check marked yes](https://docs.databricks.com/gcp/en/images/icons/check.png) Lakehouse//RT

> [!NOTE]
> **Preview**
>
> Support for GEOGRAPHY values is in [Public Preview](https://docs.databricks.com/gcp/en/release-notes/release-types.md). Support for GEOMETRY values is [generally available](https://docs.databricks.com/gcp/en/release-notes/release-types.md).

> [!NOTE]
>
> This feature is not available on Databricks SQL Classic warehouses. To learn more about Databricks SQL warehouses, see [SQL warehouse types](https://docs.databricks.com/gcp/en/compute/sql-warehouse/warehouse-types.md).

Returns the total number of rings of the input polygon or multipolygon, including exterior and interior rings. For a multipolygon, returns the sum of all rings across all polygons.

## Syntax

```
st_nrings ( geoExpr )
```

## Arguments

* `geoExpr`: A `GEOGRAPHY` or `GEOMETRY` value.

## Returns

An `INTEGER` value that represents the total number of rings in the input polygon or multipolygon.

## Notes

The function returns `NULL` if the input is `NULL`.

## Error conditions

* If `geoExpr` is not a polygon or multipolygon, the function returns [ST\_INVALID\_ARGUMENT.INVALID\_TYPE](https://docs.databricks.com/gcp/en/error-messages/st-invalid-argument-error-class.md#invalid_type).

## Examples

```sql
-- Example taking an empty 2D polygon GEOMETRY.
> SELECT st_nrings(st_geomfromtext('POLYGON EMPTY'));
  0
-- Example taking a 4D polygon GEOGRAPHY with two rings (one exterior, one interior).
> SELECT st_nrings(st_geogfromtext('POLYGON ZM ((0 0 111 -11,10 0 222 -22,0 10 333 -33,0 0 444 -44),(1 1 555 -55,4 1 666 -66,1 4 777 -77,1 1 888 -88))'));
  2
-- Example taking an empty 3DZ multipolygon GEOMETRY.
> SELECT st_nrings(st_geomfromtext('MULTIPOLYGON Z EMPTY', 4326));
  0
-- Example taking a multipolygon GEOGRAPHY with four rings across two polygons.
> SELECT st_nrings(st_geogfromtext('MULTIPOLYGON (((0 0,10 0,10 10,0 10,0 0),(1 1,4 1,4 4,1 4,1 1),(5 5,6 5,6 6,5 6,5 5)),((20 20,30 20,30 30,20 30,20 20)))'));
  4
```

## Related functions

* [`st_exteriorring` function](https://docs.databricks.com/gcp/en/sql/language-manual/functions/st_exteriorring.md)
* [`st_interiorringn` function](https://docs.databricks.com/gcp/en/sql/language-manual/functions/st_interiorringn.md)
* [`st_numinteriorrings` function](https://docs.databricks.com/gcp/en/sql/language-manual/functions/st_numinteriorrings.md)
* [`st_makepolygon` function](https://docs.databricks.com/gcp/en/sql/language-manual/functions/st_makepolygon.md)
