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

UUID type is never used for user variables

Details

    • Bug
    • Status: Closed (View Workflow)
    • Major
    • Resolution: Not a Bug
    • 10.7(EOL), 10.8(EOL), 10.9(EOL), 10.10(EOL), 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

            bar Alexander Barkov added a comment - - edited

            User variables support only four data types:

            • VARCHAR
            • INT
            • DOUBLE
            • DECIMAL

            The same problem is repeatable with any other data types:

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

            Notice, DATE was converted to VARCHAR.

            Supporting precise data types in user variables is currently not on our todo.

            bar Alexander Barkov added a comment - - edited User variables support only four data types: VARCHAR INT DOUBLE DECIMAL The same problem is repeatable with any other data types: MariaDB [test]> SET @date=CURRENT_DATE(); Query OK, 0 rows affected (0.000 sec)   MariaDB [test]> SELECT VARIABLE_TYPE FROM information_schema.user_variables WHERE VARIABLE_NAME = 'date'; +---------------+ | VARIABLE_TYPE | +---------------+ | VARCHAR | +---------------+ 1 row in set (0.001 sec) Notice, DATE was converted to VARCHAR. Supporting precise data types in user variables is currently not on our todo.

            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.