[MDEV-20785] Converting INET6 to CHAR(39) produces garbage without a warning Created: 2019-10-09  Updated: 2019-10-09  Resolved: 2019-10-09

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

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

Issue Links:
Relates
relates to MDEV-274 The data type for IPv6/IPv4 addresses... Closed
relates to MDEV-20784 Testing for MDEV-274 (INET6, data typ... Closed

 Description   

CAST from INET6 to CHAR(39) works fine, so one could expect that ALTER TABLE works too. It does, without a warning, but resulting contents looks like garbage:

CREATE OR REPLACE TABLE t1 (a INET6);
INSERT INTO t1 VALUES ('2001:db8::ff00:42:8329');
SELECT CAST(a AS CHAR(39)) FROM t1;
ALTER TABLE t1 MODIFY a CHAR(39);
SELECT * FROM t1;

MariaDB [test]> SELECT CAST(a AS CHAR(39)) FROM t1;
+------------------------+
| CAST(a AS CHAR(39))    |
+------------------------+
| 2001:db8::ff00:42:8329 |
+------------------------+
1 row in set (0.000 sec)
 
MariaDB [test]> ALTER TABLE t1 MODIFY a CHAR(39);
Query OK, 1 row affected (0.843 sec)               
Records: 1  Duplicates: 0  Warnings: 0
 
MariaDB [test]> SELECT * FROM t1;
+---------------------+
| a                   |
+---------------------+
¸      ÿ  Bƒ)    |
+---------------------+
1 row in set (0.001 sec)



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

It erroneously writes binary representation to the CHAR column:

CREATE OR REPLACE TABLE t1 (a INET6);
INSERT INTO t1 VALUES ('2001:db8::ff00:42:8329');
ALTER TABLE t1 MODIFY a CHAR(39);
SELECT HEX(a) FROM t1; -- Notice HEX()

+----------------------------------+
| HEX(a)                           |
+----------------------------------+
| 20010DB8000000000000FF0000428329 |
+----------------------------------+

Should be changed to write text representation when altering to CHAR/TEXT.

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