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

Add ability to handle Oracle Identity columns in ORACLE Mode

    XMLWordPrintable

Details

    Description

      In Oracle 12c Oracle added the ability to create a numeric identity column that adds incrementing numbers automatically. In other words they added the AUTO_INCREMENT functionality without having to explicitly create a sequence first.
      Example syntax:

      CREATE TABLE regions
        (
          region_id NUMBER GENERATED BY DEFAULT AS IDENTITY
          START WITH 5 PRIMARY KEY,
          region_name VARCHAR2( 50 ) NOT NULL
        );
      

      However, if that code is executed as is in MariaDB with Oracle mode on you get the following error:

      ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'BY DEFAULT AS IDENTITY
          START WITH 5 PRIMARY KEY,
        region_name VARCHAR2( ...' at line 3
      

      For now to maintain the same functionality as the Oracle syntax above, the create table would need to be modified to the below code snippet:

      CREATE TABLE regions
      (
        region_id   NUMBER PRIMARY KEY AUTO_INCREMENT,
        region_name VARCHAR2( 50 ) NOT NULL
      ) AUTO_INCREMENT = 5;
      

      Let's add the identity column syntax to Oracle mode to so we can minimize schema code rewrites.

      It appears that behind the scenes Oracle is still making a sequence, but doesn't require explicitly creating it ahead of time. For more details view https://oracle-base.com/articles/12c/identity-columns-in-oracle-12cr1.

      Attachments

        Activity

          People

            Unassigned Unassigned
            kyle.hutchinson Kyle Hutchinson
            Votes:
            0 Vote for this issue
            Watchers:
            2 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.