Converts an IPv4 address in BINARY format to a BIGINT value.
Syntax
BIGINT NET_IPV4_TO_INT64(BINARY <addr>)
Parameters
addr: Required. An IPv4 address of the BINARY data type. IPv6 addresses are not supported.
Return value
Returns a BIGINT in the range [0, 4294967295].
The least significant bits of the IP address map to the least significant bits of the returned integer. For example, 0.0.0.1 returns 1, and 0.0.1.255 returns 511.
If addr is NULL, the function returns NULL. If addr is not a valid IPv4 address in BINARY format, the function returns an error.
Examples
NET_IPV4_TO_INT64 accepts BINARY input, so pass STRING addresses through NET_SAFE_IP_FROM_STRING first to convert them.
-- 48.49.50.51 → 808530483
-- (48 × 16,777,216) + (49 × 65,536) + (50 × 256) + 51 = 808,530,483
SELECT NET_IPV4_TO_INT64(NET_SAFE_IP_FROM_STRING('48.49.50.51'));
-- 0.0.0.1 → 1
SELECT NET_IPV4_TO_INT64(NET_SAFE_IP_FROM_STRING('0.0.0.1'));
-- 0.0.1.255 → 511
SELECT NET_IPV4_TO_INT64(NET_SAFE_IP_FROM_STRING('0.0.1.255'));
-- NULL input → NULL
SELECT NET_IPV4_TO_INT64(NULL);
Related functions
NET_IPV4_TO_INT64 is a network function. For more information, see Network functions.