Uploaded image for project: 'MariaDB Server'
  1. MariaDB Server
  2. MDEV-9333

Inconsistency when copying from INT to ENUM

    XMLWordPrintable

Details

    • Bug
    • Status: Open (View Workflow)
    • Minor
    • Resolution: Unresolved
    • 5.5, 10.0, 10.1, 10.2
    • 10.2
    • OTHER
    • None

    Description

      In this script:

      DROP TABLE IF EXISTS t1;
      CREATE TABLE t1 (a INT, b ENUM('2','3'));
      INSERT INTO t1 VALUES(2,'2');
      UPDATE t1 SET b=a;
      SELECT b FROM t1;

      copying is done using val_int() method of the field "a", which returns 2 and then further converts to ENUM value[2], which is '3'. So the script returns:

      +------+
      | b    |
      +------+
      | 3    |
      +------+

      The same behavior is demonstrated in this script:

      DROP TABLE IF EXISTS t1,t2;
      CREATE TABLE t1 (a INT);
      INSERT INTO t1 VALUES (2);
      CREATE TABLE t2 (b ENUM('2','3'));
      INSERT INTO t2 SELECT * FROM t1;
      SELECT *FROM t2;

      +------+
      | b    |
      +------+
      | 3    |
      +------+

      Now if I use ALTER:

      DROP TABLE IF EXISTS t1;
      CREATE TABLE t1 (a INT);
      INSERT INTO t1 VALUES(2);
      ALTER TABLE t1 CHANGE a b ENUM('2','3');
      SELECT * FROM t1;

      it goes through val_str() of the field "a" which returns string '2', so the result is:

      +------+
      | b    |
      +------+
      | 2    |
      +------+

      All three cases should return the same result.

      Attachments

        Activity

          People

            bar Alexander Barkov
            bar Alexander Barkov
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:

              Git Integration

                Error rendering 'com.xiplink.jira.git.jira_git_plugin:git-issue-webpanel'. Please contact your Jira administrators.