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

ENUM value is empty string, if trigger on the table

    XMLWordPrintable

Details

    Description

      If a table has an ENUM column without a default value, then when inserting a row without specifying this column, the first ENUM value is inserted. This is expected and matches the documentation:
      https://mariadb.com/docs/server/reference/data-types/string-data-types/enum

      CREATE TABLE `enum_test` (
       `id` int(10) UNSIGNED NOT NULL AUTO_INCREMENT,
       `enum_column` enum('N','Y') NOT NULL,
       `datum` datetime NOT NULL,
       PRIMARY KEY (`id`)
      ) ENGINE=InnoDB
       DEFAULT CHARSET=utf8mb4
       COLLATE=utf8mb4_general_ci;
       
      INSERT INTO enum_test (datum) VALUES (NOW());
      SELECT * FROM enum_test;
       
      +----+-------------+---------------------+
      | id | enum_column | datum               |
      +----+-------------+---------------------+
      |  1 | N           | 2025-08-22 10:05:36 |
      +----+-------------+---------------------+
      

      However, if a BEFORE trigger is added to this table, then when inserting a row without specifying the ENUM column, instead of the first ENUM value, an empty string ('') gets inserted:

      DELIMITER $$
      CREATE TRIGGER `test_trigger` BEFORE UPDATE ON `enum_test` FOR EACH ROW BEGIN
      END
      $$
      DELIMITER ;
       
      INSERT INTO enum_test (datum) VALUES (NOW());
      SELECT * FROM enum_test;
       
      +----+-------------+---------------------+
      | id | enum_column | datum               |
      +----+-------------+---------------------+
      |  1 | N           | 2025-08-22 10:05:36 |
      |  2 |             | 2025-08-22 10:05:52 |
      +----+-------------+---------------------+
      

      Affected versions: 10.6.23, 10.11.14, 11.4.8, 11.8.3, 12.0.2, 12.1.1

      Not affected versions: 11.2.2, 11.2.6, 11.3.2

      Attachments

        Issue Links

          Activity

            People

              serg Sergei Golubchik
              LaySoft Lay András
              Votes:
              0 Vote for this issue
              Watchers:
              5 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.