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

Provide a way to add/remove/modify enum items without specifying existing items

Details

    Description

      It would be great if MariaDB SQL allowed for adding and ideally also removing/modifying individual enum items without having to specify all the existing items in the enum.

      The syntax may be like this:

      ALTER TABLE dog
      MODIFY size ENUM ADD VALUE 'large';

      ALTER TABLE dog
      MODIFY size ENUM RENAME VALUE 'large', 'very big';

      ALTER TABLE dog
      MODIFY size ENUM DROP VALUE 'very big';

      or something similar. We can borrow some syntax from PostgreSQL which has "enum types":

      https://www.postgresql.org/docs/16/sql-createtype.html
      https://www.postgresql.org/docs/16/sql-altertype.html

      but adding CREATE/ATER TYPE is a more complex task.

      Attachments

        Activity

          this could be possible with a stored procedure and dynamic SQL, couldn't it? Like

          select colunm_type into old_enum information_schema.columns where table_schema=db and table_name=tbl and column_name=col;
          

          (here db, tbl, col are parameters of the stored procedure), then, like

          select regexp_replace(old_enum, '.$', concat(',',more_values,')')) into new_enum;
          

          (more_values is also a parameter)
          and then ALTER TABLE in the EXECUTE IMMEDIATE.

          So, adding enum values would be something like

          call add_values_to_enum('my_database', 'table_1', 'enum_column', 'new_value,another_new_value');
          

          serg Sergei Golubchik added a comment - this could be possible with a stored procedure and dynamic SQL, couldn't it? Like select colunm_type into old_enum information_schema.columns where table_schema=db and table_name=tbl and column_name=col; (here db , tbl , col are parameters of the stored procedure), then, like select regexp_replace(old_enum, '.$' , concat( ',' ,more_values, ')' )) into new_enum; ( more_values is also a parameter) and then ALTER TABLE in the EXECUTE IMMEDIATE . So, adding enum values would be something like call add_values_to_enum( 'my_database' , 'table_1' , 'enum_column' , 'new_value,another_new_value' );

          People

            ralf.gebhardt Ralf Gebhardt
            valerii Valerii Kravchuk
            Votes:
            1 Vote for this issue
            Watchers:
            3 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.