Categories:

Conversion functions, IPADDRESS functions

TO_IPADDRESS

Converts the input expression to an IPADDRESS value.

See also:

Syntax

TO_IPADDRESS( <string_expr> )

Arguments

string_expr

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

Returns

The return type is IPADDRESS.

For NULL input, the output is NULL.

If the input isn’t a valid IP address, the function raises an error.

Usage notes

Examples

The following example converts a string to an IPADDRESS value:

SELECT TO_IPADDRESS('192.0.2.1');
+---------------------------+
| TO_IPADDRESS('192.0.2.1') |
|---------------------------|
| 192.0.2.1                 |
+---------------------------+

The following example converts an IPv6 address that contains leading zeros and returns its RFC 5952 canonical form:

SELECT TO_IPADDRESS('2001:0db8:0000:0000:0000:0000:0000:0001');
+---------------------------------------------------------+
| TO_IPADDRESS('2001:0DB8:0000:0000:0000:0000:0000:0001') |
|---------------------------------------------------------|
| 2001:db8::1                                             |
+---------------------------------------------------------+