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

ALTER TABLE wrongly checks for field's default value if AFTER is used

Details

    Description

      See the following test script:

      CREATE TABLE test(
      t text NOT NULL,
      d date NOT NULL
      );
       
      insert into test values ("x",CURRENT_DATE());
       
      SET SESSION sql_mode = "STRICT_TRANS_TABLES,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION,NO_ZERO_DATE,NO_ZERO_IN_DATE";
       
      ALTER TABLE test
      CHANGE d d DATE  NOT NULL AFTER t,
       ADD i text NOT NULL AFTER d
      ;
      

      Resulting in
      Error (1292): Incorrect date value: '0000-00-00' for column `test`.`d` at row 1

      As you can see this is totally wrong, there is no such value 0000-00-00 in this table, and the alter statement should succeed.

      Attachments

        Issue Links

          Activity

            alice Alice Sherepa added a comment -

            Thanks! I repeated as described on 5.5-10.5 with Myisam table, while no error with InnoDB table on 5.5-10.2,
            but error on 10.3-10.5

             
            --source include/have_innodb.inc
             
            CREATE TABLE t1(t int, d date NOT NULL) engine=innodb;
            INSERT INTO t1 VALUES (1,'2001-1-1');
            SET sql_mode = "NO_ZERO_DATE";
            ALTER TABLE t1 change d d DATE NOT NULL AFTER t, ADD i int ;
            

            query 'ALTER TABLE test change d d DATE NOT NULL AFTER t, ADD i int ' failed: 1292: Incorrect date value: '0000-00-00' for column `test`.`t1`.`d` at row 1
            

            alice Alice Sherepa added a comment - Thanks! I repeated as described on 5.5-10.5 with Myisam table, while no error with InnoDB table on 5.5-10.2, but error on 10.3-10.5 --source include/have_innodb.inc   CREATE TABLE t1(t int , d date NOT NULL ) engine=innodb; INSERT INTO t1 VALUES (1, '2001-1-1' ); SET sql_mode = "NO_ZERO_DATE" ; ALTER TABLE t1 change d d DATE NOT NULL AFTER t, ADD i int ; query 'ALTER TABLE test change d d DATE NOT NULL AFTER t, ADD i int ' failed: 1292: Incorrect date value: '0000-00-00' for column `test`.`t1`.`d` at row 1

            People

              serg Sergei Golubchik
              mokraemer Marc
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Git Integration

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