メインコンテンツまでスキップ

ip_host function

Applies to: check marked yes Databricks Runtime 18.2 and above

Returns the canonical representation of an IPv4 or IPv6 address.

Syntax​

ip_host ( ip )

Arguments​

  • ip: A STRING or BINARY value representing a valid IPv4 or IPv6 address.

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.

Error conditions​

  • If the input is not a valid IPv4 or IPv6 address, the function returns INVALID_IP_ADDRESS.

Examples​

SQL
> SELECT ip_host('192.168.1.5');
192.168.1.5

> SELECT ip_host('2001:0db8:0000:0000:0000:0000:0000:0001');
2001:db8::1

> SELECT ip_host('2001:DB8::1');
2001:db8::1

> SELECT ip_host('::ffff:192.0.2.128');
::ffff:192.0.2.128

> SELECT hex(ip_host(X'C0A80101'));
C0A80101

> SELECT ip_host(NULL);
NULL

> SELECT ip_host('invalid.ip');
Error: INVALID_IP_ADDRESS