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

Wrong result caused by UNSIGNED column and UNION ALL

Details

    • Bug
    • Status: Closed (View Workflow)
    • Major
    • Resolution: Duplicate
    • 10.2.12, 5.5(EOL), 10.0(EOL), 10.1(EOL), 10.2(EOL)
    • N/A
    • Data types

    Description

      SELECT returns wrong data when UNION ALL is used and first table has unsigned column and second table has signed data in this column.

      Example:

      CREATE TABLE `pokus` (
        `id` INT NOT NULL,
        `unsigned_column` SMALLINT UNSIGNED NOT NULL,
        PRIMARY KEY (`id`));
       
      INSERT INTO `pokus` (`id`, `unsigned_column`) VALUES ('1', '5');
       
      SELECT id, unsigned_column FROM pokus
      UNION ALL
      SELECT id, -unsigned_column FROM pokus;
      

      result:

      '1', '5'
      '1', '0'
      

      Second row has 0 in second column, it should have -5.

      Attachments

        Issue Links

          Activity

            alice Alice Sherepa added a comment -

            Thanks for the report!
            Reproducible on MariaDB 5.5-10.2, mysql 5.7.19
            Fixed in MariaDB 10.3.1, commit 705fc43eaafccd7a41e5 by Alexander Barkov.

            	CREATE TABLE `t1` (`u` INT UNSIGNED);
            	INSERT INTO `t1` VALUES ('5');
            	SELECT u FROM t1 UNION  SELECT -u FROM t1;
            	DROP TABLE t1;
            

            alice Alice Sherepa added a comment - Thanks for the report! Reproducible on MariaDB 5.5-10.2, mysql 5.7.19 Fixed in MariaDB 10.3.1, commit 705fc43eaafccd7a41e5 by Alexander Barkov. CREATE TABLE `t1` (`u` INT UNSIGNED); INSERT INTO `t1` VALUES ( '5' ); SELECT u FROM t1 UNION SELECT -u FROM t1; DROP TABLE t1;
            bar Alexander Barkov added a comment - - edited

            Fixing in versions prior to 10.3 is not possible.
            Please use a CAST(..AS DECIMAL(M,N)) as a workaround.

            This was fixed in 10.3 in a commit for MDEV-12775, which was a huge and intrusive patch and we cannot realistically backport it into a GA release.
            See "git show 705fc43eaafccd7a41e541f3149a917850f4e2fb" in the 10.3 branch.

            bar Alexander Barkov added a comment - - edited Fixing in versions prior to 10.3 is not possible. Please use a CAST(..AS DECIMAL(M,N)) as a workaround. This was fixed in 10.3 in a commit for MDEV-12775 , which was a huge and intrusive patch and we cannot realistically backport it into a GA release. See "git show 705fc43eaafccd7a41e541f3149a917850f4e2fb" in the 10.3 branch.

            People

              bar Alexander Barkov
              PavelCibulka Pavel Cibulka
              Votes:
              0 Vote for this issue
              Watchers:
              4 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.