[MDEV-18208] enum ('0','1','2','3') -> int type causes data increment '0' -> 1 ('x' -> x+1) Created: 2019-01-11  Updated: 2019-01-11  Resolved: 2019-01-11

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

Type: Bug Priority: Major
Reporter: Daniel Black Assignee: Unassigned
Resolution: Not a Bug Votes: 0
Labels: types, upstream


 Description   

https://dbfiddle.uk/?rdbms=mariadb_10.3&fiddle=a104c74c56d1a9e25ae1e5104016b774

 
 
    create table x (y enum ('0','1','2','3') );
 
 
    insert into x values ('1'),('0'),('2'),('3')
 
 
    select * from x
 
    | y  |
    | :- |
    | 1  |
    | 0  |
    | 2  |
    | 3  |
 
    alter table x modify y tinyint unsigned;
 
 
    select * from x;
 
    |  y |
    | -: |
    |  2 |
    |  1 |
    |  3 |
    |  4 |



 Comments   
Comment by Daniel Black [ 2019-01-11 ]

Seems generic about casting any string enum to signed/unsigned int

 
    select y,cast(y as signed) as s, cast(y as unsigned) as u,cast(y as double) as d from x;
 
    y  |  s |  u |  d
    :- | -: | -: | -:
    1  |  2 |  2 |  2
    0  |  1 |  1 |  1
    2  |  3 |  3 |  3
    3  |  4 |  4 |  4

Comment by Daniel Black [ 2019-01-11 ]

This converting the order in the enum list as the int rather than a conversion of the value.

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