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

Computed default for INVISIBLE column is ignored in INSERT

    XMLWordPrintable

Details

    Description

      When a table has an INVISIBLE column with a computed default, said default is only used in an INSERT if said column is not specified, but other columns are. Best illustrated with an example:

      MariaDB> CREATE TABLE t1(c1 INT NOT NULL PRIMARY KEY, c2 INTEGER NOT NULL DEFAULT (c1 + 1) INVISIBLE);
      MariaDB> INSERT INTO t1 VALUES(1),(2);
      MariaDB> INSERT INTO t1(c1) VALUES(3),(4);
      MariaDB> INSERT INTO t1 VALUES(5),(6);
      MariaDB [test]> SELECT c1, c2 FROM t1;
      +----+----+
      | c1 | c2 |
      +----+----+
      |  1 |  0 |
      |  2 |  0 |
      |  3 |  4 |
      |  4 |  5 |
      |  5 |  0 |
      |  6 |  0 |
      +----+----+
      

      As can be seen, when doing an INSERT without specifying the columns, 0 is inserted and the defined DEFAULT is ignored. If an INSERT specifying which columns to insert though, the DEFAULT is computed appropriately.

      Attachments

        Issue Links

          Activity

            People

              midenok Aleksey Midenkov
              karlsson Anders Karlsson
              Votes:
              0 Vote for this issue
              Watchers:
              5 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.