ip_version function
Applies to: Databricks Runtime 18.2 and above
Beta
This feature is in Beta. Workspace admins can control access to this feature from the Previews page. See Manage Databricks previews.
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: ASTRINGorBINARYvalue 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.
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