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

INSERT with no fields names on a table with Virtual Columns raises an error

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Not a Bug
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: None
    • Labels:
      None

      Description

      One can INSERT a row into a table without specifying the fields names. But if the table contains Virtual Columns, you don't include those values in the statement. But then, MariaDB says that column count doesn't match.

      MariaDB [test]> DROP VIEW IF EXISTS `t1`;
      Query OK, 0 rows affected, 1 warning (0.00 sec)

      MariaDB [test]> DROP TABLE IF EXISTS `t1`;
      Query OK, 0 rows affected (0.46 sec)

      MariaDB [test]> CREATE TABLE `t1` (
      -> `a` INTEGER UNSIGNED NULL DEFAULT NULL,
      -> `b` INTEGER UNSIGNED GENERATED ALWAYS AS (`a` + 1) PERSISTENT
      -> )
      -> ENGINE = Aria
      -> ROW_FORMAT = PAGE;
      Query OK, 0 rows affected (0.18 sec)

      MariaDB [test]> INSERT INTO `t1` VALUES (1);
      ERROR 1136 (21S01): Column count doesn't match value count at row 1

        Gliffy Diagrams

          Attachments

            Activity

            Hide
            elenst Elena Stepanova added a comment -

            Hi Federico,

            This behavior is consistent with other cases when a column has a default value or is calculated automatically, e.g. is an auto-increment column. In case of virtual columns, if you want to insert without specifying field names, you can use the 'default' keyword:

            INSERT INTO `t1` VALUES (1, default);

            I suppose NULL should also work.

            Show
            elenst Elena Stepanova added a comment - Hi Federico, This behavior is consistent with other cases when a column has a default value or is calculated automatically, e.g. is an auto-increment column. In case of virtual columns, if you want to insert without specifying field names, you can use the 'default' keyword: INSERT INTO `t1` VALUES (1, default); I suppose NULL should also work.

              People

              • Assignee:
                elenst Elena Stepanova
                Reporter:
                f_razzoli Federico Razzoli
              • Votes:
                0 Vote for this issue
                Watchers:
                3 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: