INET6
IPv6 address data type. Stores IPv6 addresses as 16-byte binary strings, also supporting IPv4 addresses via mapping.
Syntax
INET6Description
The INET6 data type is intended for storage of IPv6 addresses, as well as IPv4 addresses assuming conventional mapping of IPv4 addresses into IPv6 addresses.
Both short and long IPv6 notation are permitted, according to RFC-5952.
Values are stored as a 16-byte fixed length binary string, with most significant byte first.
Storage engines see
INET6asBINARY(16).Clients see
INET6asCHAR(39)and get text representation on retrieval.
The IPv4-compatible notation is considered as deprecated. It is supported for compatibility with the INET6_ATON function, which also understands this format. It's recommended to use the mapped format to store IPv4 addresses in INET6.
When an IPv4 mapped (or compatible) value is stored in INET6, it still occupies 16 bytes:
Retrieval
On retrieval, in the client-server text protocol, INET6 values are converted to the short text representation, according to RFC-5952, that is with all leading zeroes in each group removed and with consequent zero groups compressed.
Besides creating one's own stored function, there is no a way to retrieve an INET6 value using long text representation.
Casting
CAST from a character string to
INET6understands addresses in short or long text notation (including IPv4 mapped and compatible addresses).NULLis returned if the format is not understood.CASTfrom a binary string toINET6requires a 16-byte string as an argument.NULLis returned if the argument length is not equal to 16.CASTfrom other data types toINET6first converts data to a character string, thenCASTfrom character string toINET6is applied.CASTfromINET6to CHAR returns short text address notation.CASTfromINET6to BINARY returns its 16-byte binary string representation.CASTfromINET6to data types other than CHAR (e.g.SIGNED,UNSIGNED,TIME, etc) returns an error.
Comparisons
An INET6 expression can be compared to:
another
INET6expressiona character string expression with a text (short or long) address representation:
a 16-byte binary string expression.
Attempting to compare INET6 to an expression of any other data type returns an error.
Mixing INET6 Values for Result
An INET6 expression can be mixed for result (i.e. UNION, CASE..THEN, COALESCE etc) with:
another
INET6expression. The resulting data type isINET6.a character string in text (short or long) address representation. The result data type is
INET6. The character string counterpart is automatically converted toINET6. If the string format is not understood, it's converted with a warning to eitherNULLor to '::', depending on theNULL-ability of the result.a 16-byte binary string. The resulting data type is
INET6. The binary string counterpart is automatically converted toINET6. If the length of the binary string is not equal to 16, it's converted with a warning toNULLor to '::' depending on theNULL-ability of the result.
Attempts to mix INET6 for result with other data types will return an error.
Mixing INET6 with other data types for LEAST and GREATEST, when mixing for comparison and mixing for result are involved at the same time, uses the same rules with mixing for result, described in the previous paragraphs.
Functions and Operators
HEX() with an INET6 argument returns a hexadecimal representation of the underlying 16-byte binary string
Arithmetic operators (+,-,*,/,MOD,DIV) are not supported for INET6. This may change in the future.
The INET6_ATON function now understands INET6 values as an argument
The prototypes of the IS_IPV4_COMPAT and I S_IPV4_MAPPED functions have changed from
a BINARY(16)toa INET6,
When the argument for the aforementioned two functions is not INET6, automatic implicit CAST to INET6 is applied. As a consequence, both functions understand arguments in both text representation and binary(16) representation.
When the argument for the aforementioned two functions is not INET6, automatic implicit CAST to INET6 is not applied.
Prepared Statement Parameters
INET6 understands both text and binary(16) address representation in prepared statement parameters (PREPARE..EXECUTE and EXECUTE IMMEDIATE statements).
Migration between BINARY(16) and INET6
You may have used BINARY(16) as a storage for IPv6 internet addresses, in combination with INET6_ATON and INET6_NTOA to respectively insert and retrieve data.
However, you can ALTER BINARY(16) columns storing IPv6 addresses to INET6. After such an alter, there is no a need to use INET6_ATON() and INET6_NTOA(). Addresses can be inserted and retrieved directly.
You may use BINARY(16) as a storage for IPv6 internet addresses, in combination with INET6_ATON and INET6_NTOA to respectively insert and retrieve data.
It is also possible to convert INET6 columns to BINARY(16) and continue using the data in combination with INET6_NTOA() and INET6_ATON().
Examples
Inserting using short text address notation:
Long text address notation:
16-byte binary string notation:
IPv4 addresses, using IPv4-mapped and IPv4-compatible notations:
IPv4 mapped (or compatible) values still occupy 16 bytes:
Casting from INET6 to anything other than CHAR returns an error:
Comparison Examples
Comparison with another INET6 expression:
With a character string expression with a text (short or long) address representation:
With a 16-byte binary string expression:
With an expression of another data type:
Mixing for Result Examples
Mixed with another INET6 expression, returning an INET6 data type:
Mixed with a character string in text (short or long) address representation:
Mixed with a 16-byte binary string:
Mixing with other data types:
Functions and Operators Examples
HEX with an INET6 argument returning a hexadecimal representation:
INET6_ATON now understands INET6 values as an argument:
IS_IPV4_COMPAT and IS_IPV4_MAPPED prototype now a BINARY(16)):
Automatic implicit CAST to INET6:
Prepared Statement Parameters Examples
Migration between BINARY(16) and INET6 Examples
Migrating to INET6:
There's no conversion you can use:
Migration from INET6 to BINARY(16):
Casting from INET4 to INET6
Casting from INET4 data types to INET6 is permitted, allowing INET4 values to be inserted into INET6 columns.
Casting from INET4 data types to INET6 is not permitted. You get an error if you try:
See Also
This page is licensed: CC BY-SA / Gnu FDL
Last updated
Was this helpful?

