Was this helpful?
IP Network Address Functions
IP network address functions operate on an IPV4 or IPV6 data type or string representing an IPv4 or IPv6 address and return a string in dotted quad or colon-hex format or an IPv4 or IPv6 binary.
INET_NTOP
INET_NTOP(expr)
Operand type: IPV4 or IPV6
Result type: Dotted quad string or colon-hex string, depending on input type
Returns a dotted quad string if the input type is IPV4 or is IPV6 and an IPV4-mapped address.
Returns an IPv6 address in rfc5952 style (zero suppressed, shortened, lowercase) if the input type is IPV6 and is not an IPv4-mapped address.
SELECT INET_NTOP(INET_PTON('172.16.254.1'))
returns
'172.16.254.1'
INET_PTON
INET_PTON(expr)
or
IPV4(expr)
Operand type: A string representing an IPv4 network address or an IPv4-mapped IPv6 address
Result type: IPv4 binary
Converts a string in standard IPv4 dotted-quad notation to its IPv4 binary equivalent.
The expression can also be an IPv4-mapped IPv6 address in the form:
"::ffff:xxx:xxx" or "::ffff:n.n.n.n"
and zero-expanded or uppercased variants of the same. An error occurs if the input is an IPv6 style string that does not represent an IPv4-mapped address.
SELECT INET_PTON('172.16.254.1');
returns the following (using hexadeximal representation):
AC10FE01
INET6_NTOP
INET6_NTOP(expr)
Operand type: IPV4 or IPV6
Result type: Colon-hex string
Returns an IPv6 address in rfc5952 style (zero suppressed, shortened, lowercase)
SELECT INET6_NTOP(INET6_PTON('172.16.254.1'))
returns
'::ffff:ac10:fe01'
INET6_PTON
INET6_PTON(expr)
or
IPV6(expr)
Operand type: A string representing an IPv4 or IPv6 network address
Result type: IPv6 binary
Converts a string in standard hex-colon notation to an IPv6 binary equivalent. Also converts an IPv4 address in either ordinary dotted-quad or "::ffff:n.n.n.n" mixed quad notation to an IPv4-mapped address ::ffff:n.n.n.n.
The input can be leading-zero-suppressed. Use one "::" to replace the longest sequence of all-zero fields and use lowercase letters. The function also accepts uppercase hexits as input.
SELECT INET6_PTON('2001:0DB8:AC10:FE01:0000:0000:0000:0000')
returns the following (using hexadecimal representation):
20010DB8AC10FE010000000000000000
UUID ([expr]) Function
With no parameters, the UUID() function creates a 128-bit universal unique identifier (UUID).
> createdb uuiddb
> sql uuiddb
* CREATE TABLE uuidtable (u1 UUID, u2 BYTE(16));
* INSERT INTO uuidtable VALUES (UUID(), UUID());
//
// Verify the length in byte format
//
* SELECT LENGTH(u1) FROM uuidtable;
//
//Length of u1 will be 36 bytes representing the length of the ASCII representation
//Length of u2 will be 16 bytes, the length of the BYTE(16) representation
//
With a parameter, UUID (expr) will convert that parameter to a UUID if possible. Character string data types must follow the 36-byte ASCII HEX format including the hyphens: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx.
UUIDs stored as BYTE(16) can be readily converted into the UUID data type.
Last modified date: 11/09/2022