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

In NO_ZERO_DATE mode, multiple timestamp fields with no default can't be created

Details

    Description

      MariaDB [test]> set sql_mode='';
      Query OK, 0 rows affected (0.00 sec)
       
      MariaDB [test]> create table t1(a timestamp, b timestamp);
      Query OK, 0 rows affected (0.11 sec)
       
      MariaDB [test]> set sql_mode = 'NO_ZERO_DATE';
      Query OK, 0 rows affected (0.00 sec)
       
      MariaDB [test]> create table t2(a timestamp, b timestamp);
      ERROR 1067 (42000): Invalid default value for 'b'
       
      MariaDB [test]> create table t2(a timestamp, b int, c timestamp);
      ERROR 1067 (42000): Invalid default value for 'c'
       
      MariaDB [test]> create table t2(a timestamp);
      Query OK, 0 rows affected (0.07 sec)
      

      Index creation is affected as well.

      MariaDB [test]> set sql_mode='';
      Query OK, 0 rows affected (0.00 sec)
       
      MariaDB [test]> create table t1(a timestamp, b timestamp);
      Query OK, 0 rows affected (0.06 sec)
       
      MariaDB [test]> set sql_mode='NO_ZERO_DATE';
      Query OK, 0 rows affected (0.00 sec)
       
      MariaDB [test]> create index idx on t1(a);
      ERROR 1067 (42000): Invalid default value for 'b'
       
      MariaDB [test]> set sql_mode='NO_ZERO_DATE,STRICT_TRANS_TABLES';
      Query OK, 0 rows affected (0.01 sec)
       
      MariaDB [test]> create index idx on t1(a);
      ERROR 1292 (22007): Incorrect datetime value: '0000-00-00 00:00:00' for column 'b' at row 1
      

      Also, it seems impossible to use current_timestamp in CREATE TABLE .. ON UPDATE.

      MariaDB [test]> set sql_mode = 'NO_ZERO_DATE';
      Query OK, 0 rows affected (0.00 sec)
       
      MariaDB [test]> create table t1 (a timestamp(5) on update current_timestamp(5));
      ERROR 1067 (42000): Invalid default value for 'a'
       
      MariaDB [test]> create table t1 (a timestamp(5) on update current_timestamp(4));
      ERROR 1294 (HY000): Invalid ON UPDATE clause for 'a' column
       
      MariaDB [test]> create table t1 (a timestamp(5) on update current_timestamp(6));
      ERROR 1067 (42000): Invalid default value for 'a'
       
      MariaDB [test]> create table t1 (a timestamp on update current_timestamp);
      ERROR 1067 (42000): Invalid default value for 'a'
      

      Attachments

        Issue Links

          Activity

            nirbhay_c,

            I don't see anything wrong with any of these examples.
            In each case when the DDL is rejected with invalid default value, one of timestamp columns is given default value '0000-00-00 00:00:00', which is not allowed with NO_ZERO_DATE.
            When you create a table with multiple TIMESTAMP columns, the legacy logic is in play, the first column gets the default value CURRENT_TIMESTAMP, but others are still zero.

            elenst Elena Stepanova added a comment - nirbhay_c , I don't see anything wrong with any of these examples. In each case when the DDL is rejected with invalid default value, one of timestamp columns is given default value '0000-00-00 00:00:00', which is not allowed with NO_ZERO_DATE . When you create a table with multiple TIMESTAMP columns, the legacy logic is in play, the first column gets the default value CURRENT_TIMESTAMP , but others are still zero.
            nirbhay_c Nirbhay Choubey (Inactive) added a comment - - edited

            So it's only the first column that gets the default. In that case, its not a bug.

            nirbhay_c Nirbhay Choubey (Inactive) added a comment - - edited So it's only the first column that gets the default. In that case, its not a bug.

            People

              Unassigned Unassigned
              nirbhay_c Nirbhay Choubey (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              2 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.