[MDEV-20783] INET6 cannot be converted to BINARY(16) (requires clarification in documentation) Created: 2019-10-09  Updated: 2019-10-10  Resolved: 2019-10-10

Status: Closed
Project: MariaDB Server
Component/s: Data types, Documentation
Affects Version/s: 10.5
Fix Version/s: 10.5.0

Type: Bug Priority: Minor
Reporter: Elena Stepanova Assignee: Alexander Barkov
Resolution: Fixed Votes: 0
Labels: None

Issue Links:
Relates
relates to MDEV-20784 Testing for MDEV-274 (INET6, data typ... Closed
relates to MDEV-20795 CAST(inet6 AS BINARY) returns wrong r... Closed
relates to MDEV-274 The data type for IPv6/IPv4 addresses... Closed
relates to MDEV-20781 Document INET6 (MDEV-274) Closed

 Description   

The description of MDEV-274 says

Values are stored as a 16-byte fixed length binary string <...>
Storage engines see INET6 as BINARY(16)

One could derive from that that INET6 can be converted into BINARY(16), but it's not the case:

CREATE OR REPLACE TABLE t1 (a INET6);
INSERT INTO t1 VALUES ('2001:db8::ff00:42:8329');
ALTER TABLE t1 MODIFY a BINARY(16);
select cast(a as binary(16)) from t1;
show warnings;

MariaDB [test]> ALTER TABLE t1 MODIFY a BINARY(16);
ERROR 1406 (22001): Data too long for column 'a' at row 1
MariaDB [test]> select cast(a as binary(16)) from t1;
+-----------------------+
| cast(a as binary(16)) |
+-----------------------+
| 2001:db8::ff00:4      |
+-----------------------+
1 row in set, 1 warning (0.000 sec)
 
MariaDB [test]> show warnings;
+---------+------+----------------------------------------------------------------+
| Level   | Code | Message                                                        |
+---------+------+----------------------------------------------------------------+
| Warning | 1292 | Truncated incorrect BINARY(16) value: '2001:db8::ff00:42:8329' |
+---------+------+----------------------------------------------------------------+
1 row in set (0.000 sec)

I assume it's expected, but it should probably be clarified in documentation.



 Comments   
Comment by Alexander Barkov [ 2019-10-09 ]

elenst thanks for reporting. I think this should be fixed, moreover it works the other way around, i.e. conversion from BINARY(16) to INET6:

CREATE OR REPLACE TABLE t1 (a BINARY(16));
INSERT INTO t1 VALUES (INET6_ATON('ffff::ffff'));
ALTER TABLE t1 MODIFY a INET6;
SELECT * FROM t1;

+------------+
| a          |
+------------+
| ffff::ffff |
+------------+

Comment by Alexander Barkov [ 2019-10-10 ]

Note, the problem with CAST will be fixed separately, in MDEV-20795.

Generated at Thu Feb 08 09:02:08 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.