VeloDB Cloud
SQL Reference
SQL Functions
Scalar Functions
Ip Functions
IPV4_STRING_TO_NUM_OR_NULL

IPV4_STRING_TO_NUM_OR_NULL

Description

Takes a string containing an IPv4 address in the format A.B.C.D (dot-separated numbers in decimal form). Returns a BIGINT number representing the corresponding IPv4 address in big endian.

Alias

  • INET_ATON

Syntax

IPV4_STRING_TO_NUM_OR_NULL(<ipv4_string>)

Parameters

ParameterDescription
<ipv4_string>String type of ipv4, like 'A.B.C.D'

Return Value

Returns a BIGINT number representing the corresponding IPv4 address in big endian.

  • If the input string is not a valid IPv4 address, NULL is returned.

Example

select ipv4_string_to_num_or_null('192.168.0.1'); 
+-------------------------------------------+ 
| ipv4_string_to_num_or_null('192.168.0.1') | 
+-------------------------------------------+ 
| 3232235521                                | 
+-------------------------------------------+ 
select str, ipv4_string_to_num_or_null(str) from ipv4_str; 
+-----------------+---------------------------------+ 
|str              | ipv4_string_to_num_or_null(str) | 
+-----------------+---------------------------------+ 
| 0.0.0.0         | 0                               | 
| 127.0.0.1       | 2130706433                      | 
| 255.255.255.255 | 4294967295                      | 
| invalid         | NULL                            | 
+-----------------+---------------------------------+