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

greatest/least with bigint unsigned maxium has unexpected results compared to 0

    XMLWordPrintable

Details

    Description

      From https://mariadb.com/kb/en/bigint-unsigned-with-least-or-greatest-unexpected-result/

      MariaDB [test]> create table i (a bigint unsigned, b bigint unsigned);
      Query OK, 0 rows affected (0.00 sec)
       
      MariaDB [test]> insert into i values (18446744073709551615,0);
      Query OK, 1 row affected (0.00 sec)
       
      MariaDB [test]> select * from i;
      Field   1:  `a`
      Catalog:    `def`
      Database:   `test`
      Table:      `i`
      Org_table:  `i`
      Type:       LONGLONG
      Collation:  binary (63)
      Length:     20
      Max_length: 20
      Decimals:   0
      Flags:      UNSIGNED NUM 
       
      Field   2:  `b`
      Catalog:    `def`
      Database:   `test`
      Table:      `i`
      Org_table:  `i`
      Type:       LONGLONG
      Collation:  binary (63)
      Length:     20
      Max_length: 1
      Decimals:   0
      Flags:      UNSIGNED NUM 
       
       
      +----------------------+------+
      | a                    | b    |
      +----------------------+------+
      | 18446744073709551615 |    0 |
      +----------------------+------+
      1 row in set (0.02 sec)
       
      MariaDB [test]>   SELECT LEAST(a,b), GREATEST(a,b), LEAST(a,cast(0 as unsigned integer)),  GREATEST(a,cast(0 as unsigned integer)) from i;
      Field   1:  `LEAST(a,b)`
      Catalog:    `def`
      Database:   ``
      Table:      ``
      Org_table:  ``
      Type:       LONGLONG
      Collation:  binary (63)
      Length:     20
      Max_length: 20
      Decimals:   0
      Flags:      UNSIGNED BINARY NUM 
       
      Field   2:  `GREATEST(a,b)`
      Catalog:    `def`
      Database:   ``
      Table:      ``
      Org_table:  ``
      Type:       LONGLONG
      Collation:  binary (63)
      Length:     20
      Max_length: 1
      Decimals:   0
      Flags:      UNSIGNED BINARY NUM 
       
      Field   3:  `LEAST(a,cast(0 as unsigned integer))`
      Catalog:    `def`
      Database:   ``
      Table:      ``
      Org_table:  ``
      Type:       LONGLONG
      Collation:  binary (63)
      Length:     20
      Max_length: 20
      Decimals:   0
      Flags:      UNSIGNED BINARY NUM 
       
      Field   4:  `GREATEST(a,cast(0 as unsigned integer))`
      Catalog:    `def`
      Database:   ``
      Table:      ``
      Org_table:  ``
      Type:       LONGLONG
      Collation:  binary (63)
      Length:     20
      Max_length: 1
      Decimals:   0
      Flags:      UNSIGNED BINARY NUM 
       
       
      +----------------------+---------------+--------------------------------------+-----------------------------------------+
      | LEAST(a,b)           | GREATEST(a,b) | LEAST(a,cast(0 as unsigned integer)) | GREATEST(a,cast(0 as unsigned integer)) |
      +----------------------+---------------+--------------------------------------+-----------------------------------------+
      | 18446744073709551615 |             0 |                 18446744073709551615 |                                       0 |
      +----------------------+---------------+--------------------------------------+-----------------------------------------+
      1 row in set (0.00 sec)
      

      Attachments

        Activity

          People

            sanja Oleksandr Byelkin
            danblack Daniel Black
            Votes:
            0 Vote for this issue
            Watchers:
            3 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.