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

UUID type is never used for user variables

    XMLWordPrintable

Details

    • Bug
    • Status: Closed (View Workflow)
    • Major
    • Resolution: Not a Bug
    • 10.7, 10.8, 10.9, 10.10, 10.11
    • N/A
    • Variables

    Description

      The UUID() function correctly returns a value of type UUID. We can easily verify this with CREATE TABLE x SELECT UUID(); and SHOW CREATE TABLE x;.

      However, the value becomes VARCHAR if we try to assign it to a user variable:

      MariaDB [(none)]> SET @uuid := UUID();
      Query OK, 0 rows affected (0.000 sec)
       
      MariaDB [(none)]> SELECT VARIABLE_TYPE FROM information_schema.user_variables WHERE VARIABLE_NAME = 'uuid'
      ;
      +---------------+
      | VARIABLE_TYPE |
      +---------------+
      | VARCHAR       |
      +---------------+
      1 row in set (0.000 sec)
      

      The same happens if we try to cast the type explicitly:

      MariaDB [(none)]> SET @uuid := CAST(UUID() AS UUID);
      Query OK, 0 rows affected (0.000 sec)
       
      MariaDB [(none)]> SELECT VARIABLE_TYPE FROM information_schema.user_variables WHERE VARIABLE_NAME = 'uuid';
      +---------------+
      | VARIABLE_TYPE |
      +---------------+
      | VARCHAR       |
      +---------------+
      1 row in set (0.000 sec)
      

      This can lead to incorrect results:

      -- with dashes:
      MariaDB [(none)]> SELECT @uuid = 'fb025246-e48d-11ed-b010-56000464509c';
      +------------------------------------------------+
      | @uuid = 'fb025246-e48d-11ed-b010-56000464509c' |
      +------------------------------------------------+
      |                                              1 |
      +------------------------------------------------+
      1 row in set (0.000 sec)
       
      -- with no dashes:
      MariaDB [(none)]> SELECT @uuid = 'fb025246e48d11edb01056000464509c';
      +--------------------------------------------+
      | @uuid = 'fb025246e48d11edb01056000464509c' |
      +--------------------------------------------+
      |                                          0 |
      +--------------------------------------------+
      1 row in set (0.000 sec)
      

      Attachments

        Issue Links

          Activity

            People

              bar Alexander Barkov
              f_razzoli Federico Razzoli
              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.