try_ip_cidr 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 CIDR block. Returns NULL instead of raising an error if the input is invalid.
Syntax
try_ip_cidr ( cidr )
Arguments
cidr: ASTRINGorBINARYvalue representing an IPv4 or IPv6 CIDR block.
Returns
The same type as the input (STRING or BINARY), representing the canonical form of the CIDR block.
The function returns NULL if the input is NULL or invalid.
Examples
SQL
> SELECT try_ip_cidr('192.168.1.100/24');
192.168.1.0/24
> SELECT try_ip_cidr('2001:0db8:0000:0000:0000:0000:0000:0001/32');
2001:db8::/32
> SELECT try_ip_cidr('::ffff:192.0.2.128/120');
::ffff:192.0.2.0/120
> SELECT hex(try_ip_cidr(X'C0A8016418'));
C0A8010018
> SELECT try_ip_cidr('invalid');
NULL
> SELECT try_ip_cidr(X'');
NULL
> SELECT try_ip_cidr(NULL);
NULL