INET_ATON
Returns an integer that represents the value of the address in host byte order, given the dotted-quad representation of a network address as a string.
Behavior Type
Syntax
INET_ATON ( expression )
Parameters
expression |
|
Notes
The following syntax converts an IPv4 address represented as the string A to an integer I. INET_ATON
trims any spaces from the right of A, calls the Linux function inet_pton, and converts the result from network byte order to host byte order using ntohl.
=> INET_ATON(VARCHAR A) -> INT8 I
If A is NULL, too long, or inet_pton returns an error, the result is NULL.
Examples
The generated number is always in host byte order. In the following example, the number is calculated as 209×256^3 + 207×256^2 + 224×256 + 40.
=> SELECT INET_ATON('209.207.224.40'); inet_aton ------------ 3520061480 (1 row) => SELECT INET_ATON('1.2.3.4'); inet_aton ----------- 16909060 (1 row) => SELECT TO_HEX(INET_ATON('1.2.3.4')); to_hex --------- 1020304 (1 row)