[MDEV-32967] Converting column containing string value '0' to enum converts to empty string Created: 2023-12-07  Updated: 2023-12-12  Resolved: 2023-12-12

Status: Closed
Project: MariaDB Server
Component/s: Data types
Affects Version/s: 10.11.6
Fix Version/s: N/A

Type: Bug Priority: Minor
Reporter: Phil Sumner Assignee: Sergei Golubchik
Resolution: Not a Bug Votes: 0
Labels: None


 Description   

Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 1624425
Server version: 10.11.6-MariaDB-1:10.11.6+maria~ubu2004-log mariadb.org binary distribution
 
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
 
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
 
MariaDB [(none)]> create database phils_test;
Query OK, 1 row affected (0.004 sec)
 
MariaDB [(none)]> use phils_test
Database changed
 
MariaDB [phils_test]> create table enum_test2(c1 varchar(20));
Query OK, 0 rows affected (0.007 sec)
 
MariaDB [phils_test]> insert into enum_test2 values ('first'),('second'),('third'), (null), ('0');
Query OK, 5 rows affected (0.003 sec)
Records: 5  Duplicates: 0  Warnings: 0
 
MariaDB [phils_test]> select * from enum_test2;
+--------+
| c1     |
+--------+
| first  |
| second |
| third  |
| NULL   |
| 0      |
+--------+
5 rows in set (0.001 sec)
 
MariaDB [phils_test]> alter table enum_test2 modify c1 enum('first','third', 'second');
Query OK, 5 rows affected (0.012 sec)
Records: 5  Duplicates: 0  Warnings: 0
 
MariaDB [phils_test]> select * from enum_test2;
+--------+
| c1     |
+--------+
| first  |
| second |
| third  |
| NULL   |
|        |
+--------+
5 rows in set (0.001 sec)
 
MariaDB [phils_test]> drop database phils_test;
Query OK, 1 row affected (0.024 sec)
 

---------------------------------

Conversion to enum should fail as '0' is not a valid value in the enum.



 Comments   
Comment by Sergei Golubchik [ 2023-12-12 ]

This is expected behavior. MariaDB notices that there is no '0' value in the ENUM and tries to interpret it as a number. And the value number 0 in the ENUM is the empty string, see https://mariadb.com/kb/en/enum/#numeric-index

Generated at Thu Feb 08 10:35:22 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.