Categories:

Conversion functions, IPADDRESS functions

TRY_TO_IPADDRESS

A special version of TO_IPADDRESS that performs the same operation (converts an input expression to an IPADDRESS value) but with error-handling support. If the conversion can’t be performed, it returns a NULL value instead of raising an error.

For more information, see the following topics:

Syntax

TRY_TO_IPADDRESS( <string_expr> )

Arguments

string_expr

A string expression that contains a valid IPv4 or IPv6 address.

Returns

Returns a value of type IPADDRESS or NULL when TO_IPADDRESS would return an error.

Examples

The following example returns NULL because the input string isn’t an IP address:

SELECT TRY_TO_IPADDRESS('not an ip');
+-------------------------------+
| TRY_TO_IPADDRESS('NOT AN IP') |
|-------------------------------|
| NULL                          |
+-------------------------------+

For examples that convert an input expression to an IPADDRESS value, see TO_IPADDRESS.