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

Combination of GENERATE ALWAYS and COLLATE does not work

    XMLWordPrintable

Details

    Description

      E.g.

      CREATE TABLE a (b varchar(1) COLLATE utf8mb4_unicode_ci GENERATED ALWAYS AS ('x'));

      leads to a syntax error near GENERATED.

      The KB syntax page for CREATE TABLE says:

      column_definition:
        data_type
          [NOT NULL | NULL] [DEFAULT default_value | (expression)]
          [AUTO_INCREMENT] [ZEROFILL] [UNIQUE [KEY] | [PRIMARY] KEY]
          [INVISIBLE] [{WITH|WITHOUT} SYSTEM VERSIONING]
          [COMMENT 'string'] [REF_SYSTEM_ID = value]
          [COLUMN_FORMAT {FIXED|DYNAMIC|DEFAULT}]
          [reference_definition]
        | data_type [GENERATED ALWAYS] 
        AS { { ROW {START|END} } | { (expression) [VIRTUAL | PERSISTENT | STORED] } }
            [UNIQUE [KEY]] [COMMENT 'string']
      

      As CHARACTER SET and COLLATE are part of "data_type" the statement above should work.

      On the other hand the parser grammer says

      field_def:
                /* empty */ { }
              | attribute_list
              | attribute_list compressed_deprecated_column_attribute
              | attribute_list compressed_deprecated_column_attribute attribute_list
              | opt_generated_always AS virtual_column_func
                vcol_opt_specifier vcol_opt_attribute
              | opt_generated_always AS ROW_SYM START_SYM opt_asrow_attribute
              | opt_generated_always AS ROW_SYM END opt_asrow_attribute
              ;
      

      As CHARACTER SET and COLLATE are part of "attribute_list", they indeed can't be combined with GENERATE ALWAYS.

      I'm not sure whether there's an actual reason for this (e.g. charset and collation always determined by the generating expression), or whether the parser syntax should indeed be fixed.

      Attachments

        Issue Links

          Activity

            People

              Unassigned Unassigned
              hholzgra Hartmut Holzgraefe
              Votes:
              0 Vote for this issue
              Watchers:
              3 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.