---
title: ip_version function
description: Learn the syntax of the ip\_version function of the SQL language in Databricks Runtime.
canonical_url: https://docs.databricks.com/gcp/en/sql/language-manual/functions/ip_version
---

# `ip_version` function

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

Returns the IP version (4 or 6) from an IPv4 or IPv6 address or CIDR block.

## Syntax

```
ip_version ( ip_or_cidr )
```

## Arguments

* `ip_or_cidr`: A `STRING` or `BINARY` value representing an IPv4 or IPv6 address or CIDR block.

## Returns

An `INTEGER`, either `4` or `6`.

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

## Error conditions

* If the input is not a valid IPv4 or IPv6 address or CIDR block, the function returns [INVALID\_IP\_ADDRESS\_OR\_CIDR\_BLOCK](https://docs.databricks.com/gcp/en/error-messages/error-classes.md#invalid_ip_address_or_cidr_block).

## Examples

```sql
> SELECT ip_version('192.168.1.5');
  4

> SELECT ip_version('192.168.1.0/24');
  4

> SELECT ip_version('2001:db8::1');
  6

> SELECT ip_version('2001:db8::/32');
  6

> SELECT ip_version('::ffff:192.168.1.1');
  6

> SELECT ip_version(X'C0A80101');
  4

> SELECT ip_version(NULL);
  NULL

> SELECT ip_version('invalid.ip');
  Error: INVALID_IP_ADDRESS_OR_CIDR_BLOCK
```

## Related functions

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