try_ip_host 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 canonical representation of an IPv4 or IPv6 address. Returns NULL instead of raising an error if the input is invalid.
Syntax
try_ip_host ( ip )
Arguments
ip: ASTRINGorBINARYvalue representing an IPv4 or IPv6 address. CIDR notation is not allowed.
Returns
The same type as the input (STRING or BINARY), representing the canonical form of the address.
The function returns NULL if the input is NULL or invalid.
Examples
SQL
> SELECT try_ip_host('192.168.1.5');
192.168.1.5
> SELECT try_ip_host('2001:0db8:0000:0000:0000:0000:0000:0001');
2001:db8::1
> SELECT try_ip_host('2001:DB8::1');
2001:db8::1
> SELECT try_ip_host('::ffff:192.0.2.128');
::ffff:192.0.2.128
> SELECT hex(try_ip_host(X'C0A80101'));
C0A80101
> SELECT try_ip_host('invalid');
NULL
> SELECT try_ip_host(X'');
NULL
> SELECT try_ip_host(NULL);
NULL