github.com/matrixorigin/matrixone@v0.7.0/test/distributed/cases/function/func_coalesce.result (about) 1 CREATE TABLE t1 (a BIGINT); 2 INSERT INTO t1 VALUES (1); 3 SELECT * FROM t1 WHERE coalesce(a) BETWEEN 0 and 0.9; 4 a 5 SELECT * FROM t1 WHERE coalesce(a)=0.9; 6 a 7 SELECT * FROM t1 WHERE coalesce(a) in (0.8,0.9); 8 a 9 SELECT * FROM t1 WHERE a BETWEEN 0 AND 0.9; 10 a 11 SELECT * FROM t1 WHERE a=0.9; 12 a 13 SELECT * FROM t1 WHERE a IN (0.8,0.9); 14 a 15 DROP TABLE t1; 16 CREATE TABLE t1 (EMPNUM INT); 17 INSERT INTO t1 VALUES (0), (2); 18 CREATE TABLE t2 (EMPNUM DECIMAL (4, 2)); 19 INSERT INTO t2 VALUES (0.0), (9.0); 20 SELECT COALESCE(t2.EMPNUM,t1.EMPNUM) AS CEMPNUM, 21 t1.EMPNUM AS EMPMUM1, t2.EMPNUM AS EMPNUM2 22 FROM t1 LEFT JOIN t2 ON t1.EMPNUM=t2.EMPNUM; 23 CEMPNUM EMPMUM1 EMPNUM2 24 0.00 0 0.00 25 2.00 2 null 26 drop table t1; 27 drop table t2; 28 CREATE TABLE t0(c0 BIGINT UNSIGNED); 29 INSERT INTO t0(c0) VALUES(NULL); 30 SELECT * FROM t0 WHERE CAST(COALESCE(t0.c0, -1) AS UNSIGNED); 31 Data truncation: data out of range: data type uint64, 32 SELECT * FROM t0 WHERE CAST(IFNULL(t0.c0, -1) AS UNSIGNED); 33 Data truncation: data out of range: data type uint64, 34 SELECT CAST(COALESCE(t0.c0, -1) AS UNSIGNED) IS TRUE FROM t0; 35 Data truncation: data out of range: data type uint64, 36 SELECT CAST(COALESCE(t0.c0, -1) AS UNSIGNED) FROM t0; 37 Data truncation: data out of range: data type uint64, 38 DROP TABLE t0; 39 CREATE TABLE t1 (a char(10), b INT); 40 INSERT INTO t1 VALUES ('', 0); 41 SELECT COALESCE(a) = COALESCE(b) FROM t1; 42 invalid argument cast to int, bad value 43 DROP TABLE t1; 44 CREATE TABLE t1 ( a INTEGER, b varchar(255) ); 45 INSERT INTO t1 VALUES (1,'z'); 46 INSERT INTO t1 VALUES (2,'y'); 47 INSERT INTO t1 VALUES (3,'x'); 48 SELECT MIN(b) AS min_b FROM t1 GROUP BY a ORDER BY COALESCE(MIN(b), 'a'); 49 min_b 50 x 51 y 52 z 53 SELECT MIN(b) AS min_b FROM t1 GROUP BY a ORDER BY COALESCE(min_b, 'a'); 54 min_b 55 x 56 y 57 z 58 SELECT MIN(b) AS min_b FROM t1 GROUP BY a ORDER BY COALESCE(MIN(b), 'a') DESC; 59 min_b 60 z 61 y 62 x 63 SELECT MIN(b) AS min_b FROM t1 GROUP BY a ORDER BY COALESCE(min_b, 'a') DESC; 64 min_b 65 z 66 y 67 x 68 DROP TABLE t1; 69 create table t1 (a bigint unsigned); 70 insert into t1 select (if(1, 9223372036854775808, 1)); 71 Data truncation: data out of range: data type int64, 72 insert into t1 select (case when 1 then 9223372036854775808 else 1 end); 73 Data truncation: data out of range: data type int64, 74 insert into t1 select (coalesce(9223372036854775808, 1)); 75 Data truncation: data out of range: data type int64, 76 select * from t1; 77 a 78 drop table t1; 79 select if(1, cast(1111111111111111111 as unsigned), 1) i,case when 1 then cast(1111111111111111111 as unsigned) else 1 end c, coalesce(cast(1111111111111111111 as unsigned), 1) co; 80 i c co 81 1111111111111111111 1111111111111111111 1111111111111111111 82 CREATE TABLE ot (col_int_nokey int(11), col_varchar_nokey varchar(1)); 83 INSERT INTO ot VALUES (1,'x'); 84 CREATE TABLE it (col_int_key int(11), col_varchar_key varchar(1)); 85 INSERT INTO it VALUES (NULL,'x'), (NULL,'f'); 86 SELECT col_int_nokey FROM ot WHERE col_varchar_nokey IN(SELECT col_varchar_key FROM it WHERE coalesce(col_int_nokey, 1) ); 87 col_int_nokey 88 1 89 drop table ot; 90 drop table it; 91 CREATE TABLE ot1(a INT); 92 CREATE TABLE ot2(a INT); 93 CREATE TABLE ot3(a INT); 94 CREATE TABLE it1(a INT); 95 CREATE TABLE it2(a INT); 96 CREATE TABLE it3(a INT); 97 INSERT INTO ot1 VALUES(0),(1),(2),(3),(4),(5),(6),(7); 98 INSERT INTO ot2 VALUES(0),(2),(4),(6); 99 INSERT INTO ot3 VALUES(0),(3),(6); 100 INSERT INTO it1 VALUES(0),(1),(2),(3),(4),(5),(6),(7); 101 INSERT INTO it2 VALUES(0),(2),(4),(6); 102 INSERT INTO it3 VALUES(0),(3),(6); 103 SELECT * 104 FROM ot1 LEFT JOIN ot2 ON ot1.a=ot2.a 105 WHERE COALESCE(ot2.a,0) IN (SELECT a FROM it3); 106 a a 107 0 0 108 1 null 109 3 null 110 5 null 111 6 6 112 7 null 113 SELECT * 114 FROM ot1 LEFT JOIN ot2 ON ot1.a=ot2.a 115 WHERE COALESCE(ot2.a,0) IN (SELECT a+0 FROM it3); 116 a a 117 0 0 118 1 null 119 3 null 120 5 null 121 6 6 122 7 null 123 SELECT * 124 FROM ot1 LEFT JOIN ot2 ON ot1.a=ot2.a 125 LEFT JOIN ot3 ON ot1.a=ot3.a 126 WHERE COALESCE(ot2.a,0) IN (SELECT a FROM it3); 127 a a a 128 0 0 0 129 1 null null 130 3 null 3 131 5 null null 132 6 6 6 133 7 null null 134 SELECT * 135 FROM ot1 LEFT JOIN ot2 ON ot1.a=ot2.a 136 LEFT JOIN ot3 ON ot1.a=ot3.a 137 WHERE COALESCE(ot3.a,0) IN (SELECT a FROM it3); 138 a a a 139 0 0 0 140 1 null null 141 2 2 null 142 3 null 3 143 4 4 null 144 5 null null 145 6 6 6 146 7 null null 147 SELECT * 148 FROM ot1 LEFT JOIN ot2 ON ot1.a=ot2.a 149 LEFT JOIN ot3 ON ot2.a=ot3.a 150 WHERE COALESCE(ot2.a,0) IN (SELECT a FROM it3); 151 a a a 152 0 0 0 153 1 null null 154 3 null null 155 5 null null 156 6 6 6 157 7 null null 158 SELECT * 159 FROM ot1 LEFT JOIN ot2 ON ot1.a=ot2.a 160 LEFT JOIN ot3 ON ot2.a=ot3.a 161 WHERE COALESCE(ot3.a,0) IN (SELECT a FROM it3); 162 a a a 163 0 0 0 164 1 null null 165 2 2 null 166 3 null null 167 4 4 null 168 5 null null 169 6 6 6 170 7 null null 171 drop table ot1; 172 drop table ot2; 173 drop table ot3; 174 drop table it1; 175 drop table it2; 176 drop table it3; 177 CREATE TABLE t1 (dt2 DATETIME(2), t3 TIMESTAMP, d DATE); 178 INSERT INTO t1 VALUES ('2001-01-01 00:00:00.12', '2001-01-01 00:00:00.567', '2002-01-01'); 179 SELECT distinct COALESCE(dt2, t3) FROM t1; 180 COALESCE(dt2, t3) 181 2001-01-01 00:00:00.120000000 182 SELECT CONCAT_WS(",", COALESCE(dt2, t3)) FROM t1; 183 CONCAT_WS(",", COALESCE(dt2, t3)) 184 2001-01-01 00:00:00.12 185 DROP TABLE t1; 186 CREATE TABLE t1 (a DATE); 187 INSERT INTO t1 VALUES ('2000-01-01'); 188 SELECT CAST(COALESCE(a,a) AS SIGNED) FROM t1; 189 cast(coalesce(a, a) as signed) 190 10957 191 SELECT CAST(COALESCE(a,a) AS CHAR) FROM t1; 192 CAST(COALESCE(a,a) AS CHAR) 193 2000-01-01 194 SELECT CAST(COALESCE(a,a) AS DECIMAL(25,3)) FROM t1; 195 invalid argument operator cast, bad value [DATE DECIMAL128] 196 SELECT CAST(COALESCE(a,a) AS DATETIME(6)) FROM t1; 197 CAST(COALESCE(a,a) AS DATETIME(6)) 198 2000-01-01 00:00:00 199 SELECT CAST(COALESCE(a,a) AS TIME(6)) FROM t1; 200 CAST(COALESCE(a,a) AS TIME(6)) 201 00:00:00 202 SELECT ROUND(COALESCE(a,a)) FROM t1; 203 invalid argument function round, bad value [DATE] 204 DROP TABLE t1; 205 CREATE TABLE t1 (a DATETIME); 206 INSERT INTO t1 VALUES ('2000-01-01 00:00:00'); 207 SELECT CAST(COALESCE(a,a) AS SIGNED) FROM t1; 208 cast(coalesce(a, a) as signed) 209 946684800 210 SELECT CAST(COALESCE(a,a) AS CHAR) FROM t1; 211 CAST(COALESCE(a,a) AS CHAR) 212 2000-01-01 00:00:00 213 SELECT CAST(COALESCE(a,a) AS DECIMAL(25,3)) FROM t1; 214 invalid argument operator cast, bad value [DATETIME DECIMAL128] 215 SELECT CAST(COALESCE(a,a) AS DATETIME(6)) FROM t1; 216 CAST(COALESCE(a,a) AS DATETIME(6)) 217 2000-01-01 00:00:00 218 SELECT CAST(COALESCE(a,a) AS TIME(6)) FROM t1; 219 CAST(COALESCE(a,a) AS TIME(6)) 220 00:00:00 221 SELECT ROUND(COALESCE(a,a)) FROM t1; 222 invalid argument function round, bad value [DATETIME] 223 DROP TABLE t1; 224 select coalesce(null); 225 coalesce(null) 226 null 227 SELECT COALESCE(NULL, NULL, NULL, 'W3Schools.com', NULL, 'Example.com'); 228 COALESCE(NULL, NULL, NULL, 'W3Schools.com', NULL, 'Example.com') 229 W3Schools.com 230 SELECT COALESCE(1)+COALESCE(1); 231 COALESCE(1)+COALESCE(1) 232 2 233 drop table if exists t1; 234 create table t1(a datetime); 235 INSERT INTO t1 VALUES (NULL), ('2001-01-01 00:00:00.12'), ('2002-01-01 00:00:00.567'); 236 select a from t1 group by a having COALESCE(a)<"2002-01-01"; 237 a 238 2001-01-01 00:00:00 239 drop table t1; 240 drop table if exists t1; 241 drop table if exists t2; 242 create table t1(a INT, b varchar(255)); 243 create table t2(a INT, b varchar(255)); 244 insert into t1 values(1, "你好"), (3, "再见"); 245 insert into t2 values(2, "日期时间"), (4, "明天"); 246 SELECT t1.a, t2.a FROM t1 JOIN t2 ON (length(COALESCE(t1.b)) = length(COALESCE(t2.b))); 247 a a 248 3 4 249 1 4 250 drop table t1; 251 drop table t2; 252 SELECT COALESCE(NULL, NULL, NULL, CAST('{"_id":"192312412512"}' AS JSON), NULL, CAST('{"_id":"192312412513"}' AS JSON)); 253 coalesce(null, null, null, cast({"_id":"192312412512"} as json), null, cast({"_id":"192312412513"} as json)) 254 {"_id": "192312412512"} 255 create table t1(a INT, b json); 256 create table t2(a INT, b json); 257 insert into t1 values(1, CAST('{"_id":"192312412512"}' AS JSON)), (3, CAST('{"_id":"192312412513"}' AS JSON)); 258 insert into t2 values(2, CAST('{"_id":"192312412514"}' AS JSON)), (4, CAST('{"_id":"192312412515"}' AS JSON)); 259 select * from t1 union all select * from t2; 260 a b 261 1 {"_id": "192312412512"} 262 3 {"_id": "192312412513"} 263 2 {"_id": "192312412514"} 264 4 {"_id": "192312412515"} 265 drop table t1; 266 drop table t2; 267 SELECT COALESCE(NULL, NULL, NULL, CAST('test' AS BLOB), NULL, CAST('1234589002' AS BLOB)); 268 coalesce(null, null, null, cast(test as blob), null, cast(1234589002 as blob)) 269 test 270 DROP table if exists t1; 271 DROP table if exists t2; 272 CREATE TABLE t1 (a INT, s BLOB); 273 INSERT INTO t1 VALUES (1, 'test'); 274 CREATE TABLE t2 (b INT, s BLOB); 275 INSERT INTO t2 VALUES (2, '1234589002'); 276 select * from t1 union all select * from t2; 277 a s 278 1 test 279 2 1234589002 280 drop table t1; 281 drop table t2; 282 SELECT COALESCE(NULL, NULL, NULL, CAST('abcdef' AS text), NULL, CAST('1234589002' AS text)); 283 coalesce(null, null, null, cast(abcdef as text), null, cast(1234589002 as text)) 284 abcdef 285 DROP table if exists t1; 286 DROP table if exists t2; 287 CREATE TABLE t1 (a INT, s text); 288 INSERT INTO t1 VALUES (1, 'abcdef'); 289 CREATE TABLE t2 (b INT, s text); 290 INSERT INTO t2 VALUES (2, 'abcdefgh'); 291 select * from t1 union all select * from t2; 292 a s 293 1 abcdef 294 2 abcdefgh 295 drop table t1; 296 drop table t2;