github.com/matrixorigin/matrixone@v1.2.0/test/distributed/cases/operator/is_not_operator.sql (about)

     1  -- @suit
     2  
     3  -- @case
     4  -- @desc:test for IS and IS NOT operator
     5  -- @label:bvt
     6  
     7  SELECT 1 IS TRUE, 0 IS FALSE;
     8  SELECT NULL IS TRUE;
     9  SELECT 1 IS NULL, 0 IS NULL, NULL IS NULL;
    10  SELECT '' IS NULL, ' ' IS NULL;
    11  
    12  DROP TABLE IF EXISTS is_test;
    13  CREATE TABLE is_test(
    14      str1 CHAR(20),
    15      str2 VARCHAR(20),
    16      d1 DATE,
    17      d2 DATETIME,
    18      d3 TIMESTAMP
    19  );
    20  
    21  INSERT INTO is_test VALUES('', ' ', NULL, NULL, NULL);
    22  INSERT INTO is_test VALUES('NULL', NULL, '0001-01-01', '2022-02-01 13:46:02', '1994-03-02');
    23  INSERT INTO is_test(str1, str2) VALUES('0', 1);
    24  INSERT INTO is_test(str1, str2) VALUES('1', 0);
    25  INSERT INTO is_test(str1, str2) VALUES(1, '1');
    26  INSERT INTO is_test(str1, str2) VALUES(0, '0');
    27  
    28  SELECT * FROM is_test WHERE str1 IS FALSE;
    29  SELECT d1, d2 FROM is_test WHERE str2 IS NOT FALSE;
    30  SELECT * FROM is_test WHERE str2 IS TRUE;
    31  SELECT * FROM is_test WHERE str1 IS FALSE;
    32  SELECT * FROM is_test WHERE str2 IS TRUE AND str1 IS TRUE;
    33  SELECT * FROM is_test WHERE LENGTH(str2) IS TRUE;
    34  SELECT * FROM is_test WHERE str1 IS TRUE OR str2 IS TRUE;
    35  
    36  DELETE FROM is_test;
    37  DROP TABLE IF EXISTS is_test;
    38  CREATE TABLE is_test(
    39      tiny TINYINT,
    40      small SMALLINT,
    41      int_test INTEGER,
    42      big BIGINT,
    43      tiny_un TINYINT UNSIGNED,
    44      small_un SMALLINT UNSIGNED,
    45      int_test_un INTEGER UNSIGNED,
    46      big_un BIGINT UNSIGNED,
    47      float_32 FLOAT,
    48      float_64 DOUBLE
    49  );
    50  
    51  INSERT INTO is_test(tiny, small, int_test, big) VALUES(0, 1, 0, -0);
    52  INSERT INTO is_test(tiny_un, small_un) VALUES(0, 1);
    53  INSERT INTO is_test(tiny_un, small_un) VALUES(0, 2);
    54  INSERT INTO is_test(float_32, float_64) VALUES(0.0, 0.00000000000000000000001);
    55  INSERT INTO is_test(float_32, float_64) VALUES(1.0, 0.4999999999999);
    56  INSERT INTO is_test(float_32, float_64) VALUES(0.51, -0.00000000000000000000001);
    57  
    58  SELECT -1 IS TRUE;
    59  SELECT 0 IS TRUE;
    60  SELECT -1 IS TRUE;
    61  SELECT 1 IS TRUE;
    62  SELECT 2 IS TRUE;
    63  SELECT -2 IS TRUE;
    64  SELECT * FROM is_test WHERE big IS TRUE;
    65  SELECT small_un FROM is_test WHERE small_un IS TRUE;
    66  SELECT float_32, float_64 FROM is_test WHERE float_32 > 0 IS FALSE;
    67  SELECT float_32, float_64 FROM is_test WHERE float_64 > 0 IS FALSE;
    68  SELECT float_32, float_64 FROM is_test WHERE float_64 = 0 IS TRUE;
    69  
    70  DELETE FROM is_test;
    71  DROP TABLE IF EXISTS is_test;
    72  
    73  CREATE TABLE is_test(
    74      b1 BOOL,
    75      b2 BOOL
    76  );
    77  
    78  INSERT INTO is_test VALUES(TRUE, FALSE);
    79  INSERT INTO is_test VALUES(1, FALSE);
    80  INSERT INTO is_test VALUES(0, TRUE);
    81  INSERT INTO is_test VALUES(FALSE, 1);
    82  INSERT INTO is_test VALUES(1, NULL);
    83  INSERT INTO is_test VALUES(NULL, 0);
    84  SELECT * FROM is_test WHERE b1 IS TRUE;
    85  SELECT * FROM is_test WHERE b1 IS NOT FALSE;
    86  SELECT * FROM is_test WHERE b2 IS FALSE;
    87  SELECT * FROM is_test WHERE b2 IS NOT FALSE;
    88  
    89  DELETE FROM is_test;
    90  DROP TABLE IF EXISTS is_test;
    91  
    92  DROP TABLE IF EXISTS t1;
    93  DROP TABLE IF EXISTS t2;
    94  CREATE TABLE t1(
    95      id INT PRIMARY KEY,
    96      name VARCHAR(20),
    97      class VARCHAR(4)
    98  );
    99  CREATE TABLE t2(
   100      id INT,
   101      nation VARCHAR(20),
   102      major VARCHAR(20)
   103  );
   104  
   105  INSERT INTO t1 VALUES('1001', 'JACK', '');
   106  INSERT INTO t1 VALUES('1002', 'TOM', '0');
   107  INSERT INTO t1 VALUES('1003', '1', '5');
   108  INSERT INTO t1 VALUES('1004', ' ', '9');
   109  INSERT INTO t2 VALUES('1001', 'BRAZIL', 'AI');
   110  INSERT INTO t2 VALUES('1002', 'IRELAND', '1');
   111  INSERT INTO t2 VALUES('1003', 'TRUE', 'AI');
   112  INSERT INTO t2 VALUES('1004', 'IRELAND', '0');
   113  SELECT id FROM t1 WHERE name IS TRUE;
   114  SELECT name, class FROM t1 WHERE name IS NOT TRUE;
   115  SELECT id, name, class FROM t1 WHERE CAST(SUBSTRING(id, 4) AS TINYINT) IS TRUE;
   116  SELECT t1.id, t1.name, t2.nation FROM t1 INNER JOIN t2 ON t1.id = t2.id WHERE t1.class IS NOT FALSE;
   117  SELECT t1.id, t2.major FROM t1 INNER JOIN t2 ON t1.id = t2.id WHERE t1.name IS TRUE;
   118  SELECT t1.id, t2.major FROM t1 INNER JOIN t2 ON t1.id = t2.id WHERE t2.nation IS TRUE;
   119  
   120  -- @case
   121  -- @desc:test for IS and IS NOT operator in function of string type
   122  -- @label:bvt
   123  SELECT * FROM t1 WHERE id = 1004 AND LENGTH(name) IS TRUE;
   124  SELECT * FROM t1 WHERE LENGTH(name) IS FALSE;
   125  SELECT id FROM t1 WHERE LENGTH(name) IS TRUE;
   126  SELECT * FROM t2 WHERE STARTSWITH(id, '1') IS TRUE;
   127  SELECT * FROM t2 WHERE ENDSWITH(id, '1') IS FALSE;
   128  SELECT * FROM t1 WHERE FIND_IN_SET('J', name) IS TRUE;
   129  
   130  DROP TABLE IF EXISTS t1;
   131  DROP TABLE IF EXISTS t2;
   132  CREATE TABLE t1(
   133      user_id VARCHAR(50) PRIMARY KEY,
   134      user_name VARCHAR(20),
   135      order_time DATETIME,
   136      pay_status BOOL
   137  );
   138  CREATE TABLE t2(
   139      order_id VARCHAR(50) PRIMARY KEY,
   140      user_id VARCHAR(50),
   141      product_id VARCHAR(50),
   142      number INT,
   143      price FLOAT
   144  );
   145  
   146  INSERT INTO t1 VALUES('7321', '小明', '2022-09-18 13:33:56', TRUE);
   147  INSERT INTO t1 VALUES('7322', '小红', '2021-07-11 22:39:18', NULL);
   148  INSERT INTO t1 VALUES('7323', '小刘', '2022-11-11 23:49:02', 1);
   149  INSERT INTO t1 VALUES('7324', ' ', '2022-12-06 09:22:19', 0);
   150  INSERT INTO t2 VALUES('9991', '7321', '', 1, 0.01);
   151  INSERT INTO t2 VALUES('9992', '7322', '1023', 0, 9.99);
   152  INSERT INTO t2 VALUES('9993', '7323', '1024', 18, 0.0);
   153  
   154  SELECT user_id, user_name FROM t1 WHERE pay_status IS NOT TRUE;
   155  SELECT user_id, user_name FROM t1 WHERE YEAR(order_time) > 1 IS TRUE;
   156  SELECT user_id, user_name FROM t1 WHERE LENGTH(MONTH(order_time))-1 IS TRUE;
   157  SELECT * FROM (SELECT * FROM t1 WHERE pay_status IS FALSE) AS t WHERE LENGTH(user_name) IS TRUE;
   158  -- Check The BOOL and INT whether works.
   159  SELECT
   160      t1.user_id, user_name, pay_status
   161  FROM t1
   162  INNER JOIN t2 ON t1.user_id = t2.user_id
   163  WHERE pay_status IS TRUE AND number IS NOT FALSE;
   164  
   165  -- Check The String and INT whether works, The INT is not just be 1 or 0.
   166  SELECT
   167      t1.user_name, order_time, product_id
   168  FROM
   169      t1
   170  LEFT JOIN t2 ON t1.user_id = t2.user_id
   171  WHERE STARTSWITH(order_id, '9') IS TRUE AND number IS TRUE;
   172  
   173  -- Check The INT and BOOL whether works, The INT is not just be 1 or 0.
   174  SELECT
   175      t1.user_name, order_time, number, price
   176  FROM
   177      t1
   178  RIGHT JOIN t2 ON t1.user_id = t2.user_id
   179  WHERE number IS TRUE AND pay_status IS NOT FALSE;
   180  
   181  DROP TABLE IF EXISTS t1;
   182  DROP TABLE IF EXISTS t2;
   183  
   184  CREATE TABLE temp(
   185      tiny TINYINT,
   186      str CHAR(20),
   187      b BOOL,
   188      int_test INT
   189  );
   190  
   191  INSERT INTO temp VALUES(NULL, '1', FALSE, 1);
   192  INSERT INTO temp VALUES(-1, '0', TRUE, 0);
   193  INSERT INTO temp VALUES(-1, '1', 0, 0);
   194  SELECT * FROM temp WHERE int_test IS FALSE;
   195  SELECT * FROM temp WHERE str IS FALSE AND int_test IS FALSE;
   196  SELECT * FROM (SELECT * FROM temp WHERE str IS TRUE) AS t WHERE int_test IS TRUE;
   197  SELECT * FROM (SELECT * FROM temp WHERE tiny IS FALSE) AS t WHERE b IS NOT TRUE;
   198  -- This SQL statement's result is different from MySQL and MO, MO's result is empty.
   199  SELECT * FROM (SELECT * FROM temp WHERE tiny IS TRUE) AS t WHERE str IS TRUE;