# IS NULL predicate select count(*) from alltypesagg$TABLE ---- TYPES bigint ---- RESULTS 10000 ==== select count(*) from alltypesagg$TABLE where tinyint_col is null ---- TYPES bigint ---- RESULTS 1000 ==== select count(*) from alltypesagg$TABLE where tinyint_col is not null ---- TYPES bigint ---- RESULTS 9000 ==== # = select count(*) from alltypesagg$TABLE where tinyint_col = 1 ---- TYPES bigint ---- RESULTS 1000 ==== select count(*) from alltypesagg$TABLE where smallint_col = 1 ---- TYPES bigint ---- RESULTS 100 ==== select count(*) from alltypesagg$TABLE where int_col = 1 ---- TYPES bigint ---- RESULTS 10 ==== select count(*) from alltypesagg$TABLE where bigint_col = 10 ---- TYPES bigint ---- RESULTS 10 ==== select count(*) from alltypesagg$TABLE where float_col = cast(1.1 as float) ---- TYPES bigint ---- RESULTS 10 ==== select count(*) from alltypesagg$TABLE where double_col = 10.1 ---- TYPES bigint ---- RESULTS 10 ==== select count(*) from alltypesagg$TABLE where date_string_col = '01/01/10' ---- TYPES bigint ---- RESULTS 1000 ==== # <> select count(*) from alltypesagg$TABLE where tinyint_col <> 1 ---- TYPES bigint ---- RESULTS 8000 ==== select count(*) from alltypesagg$TABLE where smallint_col <> 1 ---- TYPES bigint ---- RESULTS 9800 ==== select count(*) from alltypesagg$TABLE where int_col <> 1 ---- TYPES bigint ---- RESULTS 9980 ==== select count(*) from alltypesagg$TABLE where bigint_col <> 1 ---- TYPES bigint ---- RESULTS 9990 ==== select count(*) from alltypesagg$TABLE where float_col <> cast(1.1 as float) ---- TYPES bigint ---- RESULTS 9980 ==== select count(*) from alltypesagg$TABLE where double_col <> 10.1 ---- TYPES bigint ---- RESULTS 9980 ==== # < select count(*) from alltypesagg$TABLE where tinyint_col < 2 ---- TYPES bigint ---- RESULTS 1000 ==== select count(*) from alltypesagg$TABLE where smallint_col < 2 ---- TYPES bigint ---- RESULTS 100 ==== select count(*) from alltypesagg$TABLE where int_col < 2 ---- TYPES bigint ---- RESULTS 10 ==== select count(*) from alltypesagg$TABLE where bigint_col < 20 ---- TYPES bigint ---- RESULTS 10 ==== select count(*) from alltypesagg$TABLE where float_col < 2.2 ---- TYPES bigint ---- RESULTS 10 ==== select count(*) from alltypesagg$TABLE where double_col < 20.2 ---- TYPES bigint ---- RESULTS 10 ==== # > select count(*) from alltypesagg$TABLE where tinyint_col > 1 ---- TYPES bigint ---- RESULTS 8000 ==== select count(*) from alltypesagg$TABLE where smallint_col > 1 ---- TYPES bigint ---- RESULTS 9800 ==== select count(*) from alltypesagg$TABLE where int_col > 1 ---- TYPES bigint ---- RESULTS 9980 ==== select count(*) from alltypesagg$TABLE where bigint_col > 10 ---- TYPES bigint ---- RESULTS 9980 ==== select count(*) from alltypesagg$TABLE where float_col > cast(1.1 as float) ---- TYPES bigint ---- RESULTS 9980 ==== select count(*) from alltypesagg$TABLE where double_col > 10.1 ---- TYPES bigint ---- RESULTS 9980 ==== # <= select count(*) from alltypesagg$TABLE where tinyint_col <= 1 ---- TYPES bigint ---- RESULTS 1000 ==== select count(*) from alltypesagg$TABLE where smallint_col <= 1 ---- TYPES bigint ---- RESULTS 100 ==== select count(*) from alltypesagg$TABLE where int_col <= 1 ---- TYPES bigint ---- RESULTS 10 ==== select count(*) from alltypesagg$TABLE where bigint_col <= 10 ---- TYPES bigint ---- RESULTS 10 ==== select count(*) from alltypesagg$TABLE where float_col <= cast(1.1 as float) ---- TYPES bigint ---- RESULTS 10 ==== select count(*) from alltypesagg$TABLE where double_col <= 10.1 ---- TYPES bigint ---- RESULTS 10 ==== # >= select count(*) from alltypesagg$TABLE where tinyint_col >= 2 ---- TYPES bigint ---- RESULTS 8000 ==== select count(*) from alltypesagg$TABLE where smallint_col >= 2 ---- TYPES bigint ---- RESULTS 9800 ==== select count(*) from alltypesagg$TABLE where int_col >= 2 ---- TYPES bigint ---- RESULTS 9980 ==== select count(*) from alltypesagg$TABLE where bigint_col >= 20 ---- TYPES bigint ---- RESULTS 9980 ==== select count(*) from alltypesagg$TABLE where float_col >= 2.2 ---- TYPES bigint ---- RESULTS 9980 ==== select count(*) from alltypesagg$TABLE where double_col >= 20.2 ---- TYPES bigint ---- RESULTS 9980 ==== # + select SUM(tinyint_col) + SUM(smallint_col), SUM(tinyint_col + smallint_col), SUM(tinyint_col) + SUM(smallint_col) + SUM(int_col), SUM(tinyint_col + smallint_col + int_col), SUM(tinyint_col) + SUM(smallint_col) + SUM(int_col) + SUM(bigint_col), SUM(tinyint_col + smallint_col + int_col + bigint_col), SUM(tinyint_col) + SUM(smallint_col) + SUM(int_col) + SUM(bigint_col) + SUM(float_col), SUM(tinyint_col + smallint_col + int_col + bigint_col + float_col), SUM(tinyint_col) + SUM(smallint_col) + SUM(int_col) + SUM(bigint_col) + SUM(float_col) + SUM(double_col), SUM(tinyint_col + smallint_col + int_col + bigint_col + float_col + double_col) from alltypesaggnonulls$TABLE ---- TYPES bigint, bigint, bigint, bigint, bigint, bigint, double, double, double, double ---- RESULTS 540000,540000,5535000,5535000,55485000,55485000,60979499.99976754,60979499.99976754,111428999.9997675,111428999.9997676 ==== # - select -1 * SUM(tinyint_col) - SUM(smallint_col), SUM(-1 * tinyint_col - smallint_col), -1 * SUM(tinyint_col) - SUM(smallint_col) - SUM(int_col), SUM(-1 * tinyint_col - smallint_col - int_col), -1 * SUM(tinyint_col) - SUM(smallint_col) - SUM(int_col) - SUM(bigint_col), SUM(-1 * tinyint_col - smallint_col - int_col - bigint_col), -1 * SUM(tinyint_col) - SUM(smallint_col) - SUM(int_col) - SUM(bigint_col) - SUM(float_col), SUM(-1 * tinyint_col - smallint_col - int_col - bigint_col - float_col), -1 * SUM(tinyint_col) - SUM(smallint_col) - SUM(int_col) - SUM(bigint_col) - SUM(float_col) - SUM(double_col), SUM(-1 * tinyint_col - smallint_col - int_col - bigint_col - float_col - double_col) from alltypesaggnonulls$TABLE ---- TYPES bigint, bigint, bigint, bigint, bigint, bigint, double, double, double, double ---- RESULTS -540000,-540000,-5535000,-5535000,-55485000,-55485000,-60979499.99976754,-60979499.99976754,-111428999.9997675,-111428999.9997676 ==== # * select MAX(tinyint_col) * MAX(smallint_col), MAX(tinyint_col * smallint_col), MAX(tinyint_col) * MAX(smallint_col) * MAX(int_col), MAX(tinyint_col * smallint_col * int_col), MAX(tinyint_col) * MAX(smallint_col) * MAX(int_col) * MAX(bigint_col), MAX(tinyint_col * smallint_col * int_col * bigint_col), MAX(tinyint_col) * MAX(smallint_col) * MAX(int_col) * MAX(bigint_col) * MAX(float_col), MAX(tinyint_col * smallint_col * int_col * bigint_col * float_col), MAX(tinyint_col) * MAX(smallint_col) * MAX(int_col) * MAX(bigint_col) * MAX(float_col) * MAX(double_col), MAX(tinyint_col * smallint_col * int_col * bigint_col * float_col * double_col) from alltypesaggnonulls$TABLE ---- TYPES bigint, bigint, bigint, bigint, bigint, bigint, double, double, double, double ---- RESULTS 891,891,890109,890109,8892188910,8892188910,9771626610293.455,9771626610293.455,9.859473533519994e+16,9.859473533519994e+16 ==== # LIKE exprs w/ the like/regex pattern coming from a column select * from LikeTbl ---- TYPES string, string, string, string, string ---- RESULTS 'NULL','%','NULL','.*','X' 'beginning of line','begin%','not begin%','^begin.*','^not begin.*' 'eight','%eight%','n%eight%','.*eight.*','n.*eight.*' 'end of line','%line','%line end','.*line$','.*line end$' 'five','%five%','n%five%','.*five.*','n.*five.*' 'four','%four%','n%four%','.*four.*','n.*four.*' 'middle of line','%of%','%of','^.*of.*$','.*of$' 'nine','%nine%','n%nine%','.*nine.*','n.*nine.*' 'one','%one%','n%one%','.*one.*','n.*one.*' 'seven','%seven%','n%seven%','.*seven.*','n.*seven.*' 'six','%six%','n%six%','.*six.*','n.*six.*' 'ten','%ten%','n%ten%','.*ten.*','n.*ten.*' 'three','%three%','n%three%','.*three.*','n.*three.*' 'two','%two%','n%two%','.*two.*','n.*two.*' ==== select str_col, match_like_col from LikeTbl where str_col LIKE match_like_col ---- TYPES string, string ---- RESULTS 'beginning of line','begin%' 'eight','%eight%' 'end of line','%line' 'five','%five%' 'four','%four%' 'middle of line','%of%' 'nine','%nine%' 'one','%one%' 'seven','%seven%' 'six','%six%' 'ten','%ten%' 'three','%three%' 'two','%two%' ==== select str_col, match_like_col from LikeTbl where str_col NOT LIKE match_like_col ---- TYPES string, string ---- RESULTS ==== select str_col, match_like_col from LikeTbl where str_col LIKE no_match_like_col ---- TYPES string, string ---- RESULTS ==== select str_col, no_match_like_col from LikeTbl where str_col NOT LIKE no_match_like_col ---- TYPES string, string ---- RESULTS 'beginning of line','not begin%' 'eight','n%eight%' 'end of line','%line end' 'five','n%five%' 'four','n%four%' 'middle of line','%of' 'nine','n%nine%' 'one','n%one%' 'seven','n%seven%' 'six','n%six%' 'ten','n%ten%' 'three','n%three%' 'two','n%two%' ==== select str_col, match_regex_col from LikeTbl where str_col REGEXP match_regex_col ---- TYPES string, string ---- RESULTS 'beginning of line','^begin.*' 'eight','.*eight.*' 'end of line','.*line$' 'five','.*five.*' 'four','.*four.*' 'middle of line','^.*of.*$' 'nine','.*nine.*' 'one','.*one.*' 'seven','.*seven.*' 'six','.*six.*' 'ten','.*ten.*' 'three','.*three.*' 'two','.*two.*' ==== select str_col, no_match_regex_col from LikeTbl where str_col REGEXP no_match_regex_col ---- TYPES string, string ---- RESULTS ==== select str_col, match_regex_col from LikeTbl where str_col NOT REGEXP match_regex_col ---- TYPES string, string ---- RESULTS ==== select str_col, no_match_regex_col from LikeTbl where str_col NOT REGEXP no_match_regex_col ---- TYPES string, string ---- RESULTS 'beginning of line','^not begin.*' 'eight','n.*eight.*' 'end of line','.*line end$' 'five','n.*five.*' 'four','n.*four.*' 'middle of line','.*of$' 'nine','n.*nine.*' 'one','n.*one.*' 'seven','n.*seven.*' 'six','n.*six.*' 'ten','n.*ten.*' 'three','n.*three.*' 'two','n.*two.*' ==== select 1+2 ---- TYPES bigint ---- RESULTS 3 ==== select timestamp_col, to_date(timestamp_col), year(timestamp_col), month(timestamp_col), dayofmonth(timestamp_col), day(timestamp_col), weekofyear(timestamp_col), hour(timestamp_col), minute(timestamp_col), second(timestamp_col) from alltypessmall$TABLE ---- TYPES timestamp, string, int, int, int, int, int, int, int, int ---- RESULTS 2009-01-01 00:00:00,'2009-01-01',2009,1,1,1,1,0,0,0 2009-01-01 00:01:00,'2009-01-01',2009,1,1,1,1,0,1,0 2009-01-01 00:02:00.100000000,'2009-01-01',2009,1,1,1,1,0,2,0 2009-01-01 00:03:00.300000000,'2009-01-01',2009,1,1,1,1,0,3,0 2009-01-01 00:04:00.600000000,'2009-01-01',2009,1,1,1,1,0,4,0 2009-01-01 00:05:00.100000000,'2009-01-01',2009,1,1,1,1,0,5,0 2009-01-01 00:06:00.150000000,'2009-01-01',2009,1,1,1,1,0,6,0 2009-01-01 00:07:00.210000000,'2009-01-01',2009,1,1,1,1,0,7,0 2009-01-01 00:08:00.280000000,'2009-01-01',2009,1,1,1,1,0,8,0 2009-01-01 00:09:00.360000000,'2009-01-01',2009,1,1,1,1,0,9,0 2009-01-02 00:10:00.450000000,'2009-01-02',2009,1,2,2,1,0,10,0 2009-01-02 00:11:00.450000000,'2009-01-02',2009,1,2,2,1,0,11,0 2009-01-02 00:12:00.460000000,'2009-01-02',2009,1,2,2,1,0,12,0 2009-01-02 00:13:00.480000000,'2009-01-02',2009,1,2,2,1,0,13,0 2009-01-02 00:14:00.510000000,'2009-01-02',2009,1,2,2,1,0,14,0 2009-01-02 00:15:00.550000000,'2009-01-02',2009,1,2,2,1,0,15,0 2009-01-02 00:16:00.600000000,'2009-01-02',2009,1,2,2,1,0,16,0 2009-01-02 00:17:00.660000000,'2009-01-02',2009,1,2,2,1,0,17,0 2009-01-02 00:18:00.730000000,'2009-01-02',2009,1,2,2,1,0,18,0 2009-01-02 00:19:00.810000000,'2009-01-02',2009,1,2,2,1,0,19,0 2009-01-03 00:20:00.900000000,'2009-01-03',2009,1,3,3,1,0,20,0 2009-01-03 00:21:00.900000000,'2009-01-03',2009,1,3,3,1,0,21,0 2009-01-03 00:22:00.910000000,'2009-01-03',2009,1,3,3,1,0,22,0 2009-01-03 00:23:00.930000000,'2009-01-03',2009,1,3,3,1,0,23,0 2009-01-03 00:24:00.960000000,'2009-01-03',2009,1,3,3,1,0,24,0 2009-02-01 00:00:00,'2009-02-01',2009,2,1,32,5,0,0,0 2009-02-01 00:01:00,'2009-02-01',2009,2,1,32,5,0,1,0 2009-02-01 00:02:00.100000000,'2009-02-01',2009,2,1,32,5,0,2,0 2009-02-01 00:03:00.300000000,'2009-02-01',2009,2,1,32,5,0,3,0 2009-02-01 00:04:00.600000000,'2009-02-01',2009,2,1,32,5,0,4,0 2009-02-01 00:05:00.100000000,'2009-02-01',2009,2,1,32,5,0,5,0 2009-02-01 00:06:00.150000000,'2009-02-01',2009,2,1,32,5,0,6,0 2009-02-01 00:07:00.210000000,'2009-02-01',2009,2,1,32,5,0,7,0 2009-02-01 00:08:00.280000000,'2009-02-01',2009,2,1,32,5,0,8,0 2009-02-01 00:09:00.360000000,'2009-02-01',2009,2,1,32,5,0,9,0 2009-02-02 00:10:00.450000000,'2009-02-02',2009,2,2,33,6,0,10,0 2009-02-02 00:11:00.450000000,'2009-02-02',2009,2,2,33,6,0,11,0 2009-02-02 00:12:00.460000000,'2009-02-02',2009,2,2,33,6,0,12,0 2009-02-02 00:13:00.480000000,'2009-02-02',2009,2,2,33,6,0,13,0 2009-02-02 00:14:00.510000000,'2009-02-02',2009,2,2,33,6,0,14,0 2009-02-02 00:15:00.550000000,'2009-02-02',2009,2,2,33,6,0,15,0 2009-02-02 00:16:00.600000000,'2009-02-02',2009,2,2,33,6,0,16,0 2009-02-02 00:17:00.660000000,'2009-02-02',2009,2,2,33,6,0,17,0 2009-02-02 00:18:00.730000000,'2009-02-02',2009,2,2,33,6,0,18,0 2009-02-02 00:19:00.810000000,'2009-02-02',2009,2,2,33,6,0,19,0 2009-02-03 00:20:00.900000000,'2009-02-03',2009,2,3,34,6,0,20,0 2009-02-03 00:21:00.900000000,'2009-02-03',2009,2,3,34,6,0,21,0 2009-02-03 00:22:00.910000000,'2009-02-03',2009,2,3,34,6,0,22,0 2009-02-03 00:23:00.930000000,'2009-02-03',2009,2,3,34,6,0,23,0 2009-02-03 00:24:00.960000000,'2009-02-03',2009,2,3,34,6,0,24,0 2009-03-01 00:00:00,'2009-03-01',2009,3,1,60,9,0,0,0 2009-03-01 00:01:00,'2009-03-01',2009,3,1,60,9,0,1,0 2009-03-01 00:02:00.100000000,'2009-03-01',2009,3,1,60,9,0,2,0 2009-03-01 00:03:00.300000000,'2009-03-01',2009,3,1,60,9,0,3,0 2009-03-01 00:04:00.600000000,'2009-03-01',2009,3,1,60,9,0,4,0 2009-03-01 00:05:00.100000000,'2009-03-01',2009,3,1,60,9,0,5,0 2009-03-01 00:06:00.150000000,'2009-03-01',2009,3,1,60,9,0,6,0 2009-03-01 00:07:00.210000000,'2009-03-01',2009,3,1,60,9,0,7,0 2009-03-01 00:08:00.280000000,'2009-03-01',2009,3,1,60,9,0,8,0 2009-03-01 00:09:00.360000000,'2009-03-01',2009,3,1,60,9,0,9,0 2009-03-02 00:10:00.450000000,'2009-03-02',2009,3,2,61,10,0,10,0 2009-03-02 00:11:00.450000000,'2009-03-02',2009,3,2,61,10,0,11,0 2009-03-02 00:12:00.460000000,'2009-03-02',2009,3,2,61,10,0,12,0 2009-03-02 00:13:00.480000000,'2009-03-02',2009,3,2,61,10,0,13,0 2009-03-02 00:14:00.510000000,'2009-03-02',2009,3,2,61,10,0,14,0 2009-03-02 00:15:00.550000000,'2009-03-02',2009,3,2,61,10,0,15,0 2009-03-02 00:16:00.600000000,'2009-03-02',2009,3,2,61,10,0,16,0 2009-03-02 00:17:00.660000000,'2009-03-02',2009,3,2,61,10,0,17,0 2009-03-02 00:18:00.730000000,'2009-03-02',2009,3,2,61,10,0,18,0 2009-03-02 00:19:00.810000000,'2009-03-02',2009,3,2,61,10,0,19,0 2009-03-03 00:20:00.900000000,'2009-03-03',2009,3,3,62,10,0,20,0 2009-03-03 00:21:00.900000000,'2009-03-03',2009,3,3,62,10,0,21,0 2009-03-03 00:22:00.910000000,'2009-03-03',2009,3,3,62,10,0,22,0 2009-03-03 00:23:00.930000000,'2009-03-03',2009,3,3,62,10,0,23,0 2009-03-03 00:24:00.960000000,'2009-03-03',2009,3,3,62,10,0,24,0 2009-04-01 00:00:00,'2009-04-01',2009,4,1,91,14,0,0,0 2009-04-01 00:01:00,'2009-04-01',2009,4,1,91,14,0,1,0 2009-04-01 00:02:00.100000000,'2009-04-01',2009,4,1,91,14,0,2,0 2009-04-01 00:03:00.300000000,'2009-04-01',2009,4,1,91,14,0,3,0 2009-04-01 00:04:00.600000000,'2009-04-01',2009,4,1,91,14,0,4,0 2009-04-01 00:05:00.100000000,'2009-04-01',2009,4,1,91,14,0,5,0 2009-04-01 00:06:00.150000000,'2009-04-01',2009,4,1,91,14,0,6,0 2009-04-01 00:07:00.210000000,'2009-04-01',2009,4,1,91,14,0,7,0 2009-04-01 00:08:00.280000000,'2009-04-01',2009,4,1,91,14,0,8,0 2009-04-01 00:09:00.360000000,'2009-04-01',2009,4,1,91,14,0,9,0 2009-04-02 00:10:00.450000000,'2009-04-02',2009,4,2,92,14,0,10,0 2009-04-02 00:11:00.450000000,'2009-04-02',2009,4,2,92,14,0,11,0 2009-04-02 00:12:00.460000000,'2009-04-02',2009,4,2,92,14,0,12,0 2009-04-02 00:13:00.480000000,'2009-04-02',2009,4,2,92,14,0,13,0 2009-04-02 00:14:00.510000000,'2009-04-02',2009,4,2,92,14,0,14,0 2009-04-02 00:15:00.550000000,'2009-04-02',2009,4,2,92,14,0,15,0 2009-04-02 00:16:00.600000000,'2009-04-02',2009,4,2,92,14,0,16,0 2009-04-02 00:17:00.660000000,'2009-04-02',2009,4,2,92,14,0,17,0 2009-04-02 00:18:00.730000000,'2009-04-02',2009,4,2,92,14,0,18,0 2009-04-02 00:19:00.810000000,'2009-04-02',2009,4,2,92,14,0,19,0 2009-04-03 00:20:00.900000000,'2009-04-03',2009,4,3,93,14,0,20,0 2009-04-03 00:21:00.900000000,'2009-04-03',2009,4,3,93,14,0,21,0 2009-04-03 00:22:00.910000000,'2009-04-03',2009,4,3,93,14,0,22,0 2009-04-03 00:23:00.930000000,'2009-04-03',2009,4,3,93,14,0,23,0 2009-04-03 00:24:00.960000000,'2009-04-03',2009,4,3,93,14,0,24,0 ==== # IN predicate select NULL in (1, 2, 3) ---- boolean ---- NULL ==== select NULL in (1, NULL, 3) ---- boolean ---- NULL ==== select 1 in (2, NULL, 1) ---- boolean ---- true ==== select 1 in (1, NULL, 2) ---- boolean ---- true ==== select 1 in (2, NULL, 3) ---- boolean ---- NULL ==== select 1 in (2, 3, 4) ---- boolean ---- false ==== select NULL not in (1, 2, 3) ---- boolean ---- NULL ==== select NULL not in (1, NULL, 3) ---- boolean ---- NULL ==== select 1 not in (2, NULL, 1) ---- boolean ---- false ==== select 1 not in (1, NULL, 2) ---- boolean ---- false ==== select 1 not in (2, NULL, 3) ---- boolean ---- NULL ==== select 1 not in (2, 3, 4) ---- boolean ---- true ==== select count(*) from alltypesagg$TABLE where true in (bool_col, tinyint_col) ---- bigint ---- 6000 ==== select count(*) from alltypesagg$TABLE where true not in (bool_col, tinyint_col) ---- bigint ---- 4000 ==== select count(*) from alltypesagg$TABLE where 1 in (tinyint_col, smallint_col, int_col, bigint_col) ---- bigint ---- 1000 ==== select count(*) from alltypesagg$TABLE where 1 not in (tinyint_col, smallint_col, int_col, bigint_col) ---- bigint ---- 8000 ==== select count(*) from alltypesagg$TABLE where 10.1 in (tinyint_col, smallint_col, int_col, bigint_col, float_col, double_col) ---- bigint ---- 10 ==== select count(*) from alltypesagg$TABLE where 10.1 not in (tinyint_col, smallint_col, int_col, bigint_col, float_col, double_col) ---- bigint ---- 8990 ==== select count(*) from alltypesagg$TABLE where '01/01/10' in (date_string_col, string_col, 'abc') ---- bigint ---- 1000 ==== select count(*) from alltypesagg$TABLE where '01/01/10' not in (date_string_col, string_col, 'abc') ---- bigint ---- 9000 ==== select count(*) from alltypesagg$TABLE where cast('2010-01-01 00:00:00' as timestamp) in (timestamp_col) ---- bigint ---- 1 ==== select count(*) from alltypesagg$TABLE where cast('2010-01-01 00:00:00' as timestamp) not in (timestamp_col) ---- bigint ---- 9999 ==== # BETWEEN predicate select count(*) from alltypesagg$TABLE where tinyint_col between 1 and 2 ---- TYPES bigint ---- RESULTS 2000 ==== select count(*) from alltypesagg$TABLE where tinyint_col not between 1 and 2 ---- TYPES bigint ---- RESULTS 7000 ==== select count(*) from alltypesagg$TABLE where smallint_col between 1 and 20 ---- TYPES bigint ---- RESULTS 2000 ==== select count(*) from alltypesagg$TABLE where smallint_col not between 1 and 20 ---- TYPES bigint ---- RESULTS 7900 ==== select count(*) from alltypesagg$TABLE where int_col between 1 and 200 ---- TYPES bigint ---- RESULTS 2000 ==== select count(*) from alltypesagg$TABLE where int_col not between 1 and 200 ---- TYPES bigint ---- RESULTS 7990 ==== select count(*) from alltypesagg$TABLE where bigint_col between 1 and 2000 ---- TYPES bigint ---- RESULTS 2000 ==== select count(*) from alltypesagg$TABLE where bigint_col not between 1 and 2000 ---- TYPES bigint ---- RESULTS 7990 ==== select count(*) from alltypesagg$TABLE where float_col between cast(1.0 as float) and cast(110.0 as float) ---- TYPES bigint ---- RESULTS 1000 ==== select count(*) from alltypesagg$TABLE where float_col not between cast(1.0 as float) and cast(110.0 as float) ---- TYPES bigint ---- RESULTS 8990 ==== select count(*) from alltypesagg$TABLE where double_col between 1.0 and 110.0 ---- TYPES bigint ---- RESULTS 100 ==== select count(*) from alltypesagg$TABLE where double_col not between 1.0 and 110.0 ---- TYPES bigint ---- RESULTS 9890 ==== select count(*) from alltypesagg$TABLE where date_string_col between '01/01/10' and '01/05/10' ---- TYPES bigint ---- RESULTS 5000 ==== select count(*) from alltypesagg$TABLE where date_string_col not between '01/01/10' and '01/05/10' ---- TYPES bigint ---- RESULTS 5000 ==== select count(*) from alltypesagg$TABLE where timestamp_col between cast('2010-01-01 00:00:00' as timestamp) and cast('2010-01-01 01:40:00' as timestamp) ---- TYPES bigint ---- RESULTS 100 ==== select count(*) from alltypesagg$TABLE where timestamp_col not between cast('2010-01-01 00:00:00' as timestamp) and cast('2010-01-01 01:40:00' as timestamp) ---- TYPES bigint ---- RESULTS 9900 ==== // Test NOW() function. select now() ---- TYPES timestamp ---- RESULTS // Matches a single date of the form 'yyyy-MM-dd HH:mm:ss' // or 'yyyy-MM-dd HH:mm:ss.SSSSSS' regex: \d{4}-\d{2}-\d{2}\s\d{2}:\d{2}:\d{2}(\.\d{9})? ==== select now(), now(), now(), now() ---- TYPES timestamp, timestamp, timestamp, timestamp ---- RESULTS // Matches four identical timestamps separated by commas. regex: (\d{4}-\d{2}-\d{2}\s\d{2}:\d{2}:\d{2}(\.\d{9})?),\1,\1,\1 ==== select now(), now(), now(), now() from alltypestiny ---- TYPES timestamp, timestamp, timestamp, timestamp ---- RESULTS // Matches four identical timestamps separated by commas. regex: (\d{4}-\d{2}-\d{2}\s\d{2}:\d{2}:\d{2}(\.\d{9})?),\1,\1,\1 regex: (\d{4}-\d{2}-\d{2}\s\d{2}:\d{2}:\d{2}(\.\d{9})?),\1,\1,\1 regex: (\d{4}-\d{2}-\d{2}\s\d{2}:\d{2}:\d{2}(\.\d{9})?),\1,\1,\1 regex: (\d{4}-\d{2}-\d{2}\s\d{2}:\d{2}:\d{2}(\.\d{9})?),\1,\1,\1 regex: (\d{4}-\d{2}-\d{2}\s\d{2}:\d{2}:\d{2}(\.\d{9})?),\1,\1,\1 regex: (\d{4}-\d{2}-\d{2}\s\d{2}:\d{2}:\d{2}(\.\d{9})?),\1,\1,\1 regex: (\d{4}-\d{2}-\d{2}\s\d{2}:\d{2}:\d{2}(\.\d{9})?),\1,\1,\1 regex: (\d{4}-\d{2}-\d{2}\s\d{2}:\d{2}:\d{2}(\.\d{9})?),\1,\1,\1 ==== // Check that now() returns the same value when evaluated on different nodes // (alltypessmall is partitioned) select min(now()), max(now()) from alltypessmall ---- TYPES timestamp, timestamp ---- RESULTS // Matches two identical timestamps separated by commas. regex: (\d{4}-\d{2}-\d{2}\s\d{2}:\d{2}:\d{2}(\.\d{9})?),\1 ==== # Timestamp arithmetic tests (lowest timestamp_col has value 2009-01-01 00:00:00). # Add/sub years, non-function-call like version. select timestamp_col + interval 10 years, interval 10 years + timestamp_col, timestamp_col - interval 10 years from alltypes$TABLE order by id limit 1 ---- TYPES timestamp,timestamp,timestamp ---- RESULTS 2019-01-01 00:00:00,2019-01-01 00:00:00,1999-01-01 00:00:00 ==== # Add/sub years, function-call like version. select date_add(timestamp_col, interval 10 years), date_sub(timestamp_col, interval 10 years) from alltypes$TABLE order by id limit 1 ---- TYPES timestamp,timestamp ---- RESULTS 2019-01-01 00:00:00,1999-01-01 00:00:00 ==== # Add/sub months, non-function-call like version. select timestamp_col + interval 13 months, timestamp_col + interval 1 month, interval 13 months + timestamp_col, interval 1 month + timestamp_col, timestamp_col - interval 13 months, timestamp_col - interval 1 month from alltypes$TABLE order by id limit 1 ---- TYPES timestamp,timestamp,timestamp,timestamp,timestamp,timestamp ---- RESULTS 2010-02-01 00:00:00,2009-02-01 00:00:00,2010-02-01 00:00:00,2009-02-01 00:00:00,2007-12-01 00:00:00,2008-12-01 00:00:00 ==== # Add/sub months, function-call like version. select date_add(timestamp_col, interval 13 months), date_add(timestamp_col, interval 1 month), date_sub(timestamp_col, interval 13 months), date_sub(timestamp_col, interval 1 month) from alltypes$TABLE order by id limit 1 ---- TYPES timestamp,timestamp,timestamp,timestamp ---- RESULTS 2010-02-01 00:00:00,2009-02-01 00:00:00,2007-12-01 00:00:00,2008-12-01 00:00:00 ==== # Add/sub weeks, non-function-call like version. select timestamp_col + interval 2 weeks, timestamp_col + interval 53 weeks, interval 2 weeks + timestamp_col, interval 53 weeks + timestamp_col, timestamp_col - interval 2 weeks, timestamp_col - interval 53 weeks from alltypes$TABLE order by id limit 1 ---- TYPES timestamp,timestamp,timestamp,timestamp,timestamp,timestamp ---- RESULTS 2009-01-15 00:00:00,2010-01-07 00:00:00,2009-01-15 00:00:00,2010-01-07 00:00:00,2008-12-18 00:00:00,2007-12-27 00:00:00 ==== # Add/sub weeks, function-call like version. select date_add(timestamp_col, interval 2 weeks), date_add(timestamp_col, interval 53 weeks), date_sub(timestamp_col, interval 2 weeks), date_sub(timestamp_col, interval 53 weeks) from alltypes$TABLE order by id limit 1 ---- TYPES timestamp,timestamp,timestamp,timestamp ---- RESULTS 2009-01-15 00:00:00,2010-01-07 00:00:00,2008-12-18 00:00:00,2007-12-27 00:00:00 ==== # Add/sub days, non-function-call like version. select timestamp_col + interval 10 days, timestamp_col + interval 10 days, interval 10 days + timestamp_col, interval 10 days + timestamp_col, timestamp_col - interval 10 days, timestamp_col - interval 365 days from alltypes$TABLE order by id limit 1 ---- TYPES timestamp,timestamp,timestamp,timestamp,timestamp,timestamp ---- RESULTS 2009-01-11 00:00:00,2009-01-11 00:00:00,2009-01-11 00:00:00,2009-01-11 00:00:00,2008-12-22 00:00:00,2008-01-02 00:00:00 ==== # Add/sub days, function-call like version. select date_add(timestamp_col, interval 10 days), date_add(timestamp_col, interval 10 days), date_sub(timestamp_col, interval 10 days), date_sub(timestamp_col, interval 365 days) from alltypes$TABLE order by id limit 1 ---- TYPES timestamp,timestamp,timestamp,timestamp ---- RESULTS 2009-01-11 00:00:00,2009-01-11 00:00:00,2008-12-22 00:00:00,2008-01-02 00:00:00 ==== # Add/sub hours, non-function-call like version. select timestamp_col + interval 25 hours, interval 25 hours + timestamp_col, timestamp_col - interval 25 hours from alltypes$TABLE order by id limit 1 ---- TYPES timestamp,timestamp,timestamp ---- RESULTS 2009-01-02 01:00:00,2009-01-02 01:00:00,2008-12-30 23:00:00 ==== # Add/sub hours, function-call like version. select date_add(timestamp_col, interval 25 hours), date_sub(timestamp_col, interval 25 hours) from alltypes$TABLE order by id limit 1 ---- TYPES timestamp,timestamp ---- RESULTS 2009-01-02 01:00:00,2008-12-30 23:00:00 ==== # Add/sub minutes (1533 minutes are 25h33m), non-function-call like version. select timestamp_col + interval 1533 minutes, interval 1533 minutes + timestamp_col, timestamp_col - interval 1533 minutes from alltypes$TABLE order by id limit 1 ---- TYPES timestamp,timestamp,timestamp ---- RESULTS 2009-01-02 01:33:00,2009-01-02 01:33:00,2008-12-30 22:27:00 ==== # Add/sub minutes (1533 minutes are 25h33m), function-call like version. select date_add(timestamp_col, interval 1533 minutes), date_sub(timestamp_col, interval 1533 minutes) from alltypes$TABLE order by id limit 1 ---- TYPES timestamp,timestamp ---- RESULTS 2009-01-02 01:33:00,2008-12-30 22:27:00 ==== # Add/sub seconds (90033 seconds are 25h33s), non-function-call like version. select timestamp_col + interval 90033 seconds, interval 90033 seconds + timestamp_col, timestamp_col - interval 90033 seconds from alltypes$TABLE order by id limit 1 ---- TYPES timestamp,timestamp,timestamp ---- RESULTS 2009-01-02 01:00:33,2009-01-02 01:00:33,2008-12-30 22:59:27 ==== # Add/sub seconds (90033 seconds are 25h33s), function-call like version. select date_add(timestamp_col, interval 90033 seconds), date_sub(timestamp_col, interval 90033 seconds) from alltypes$TABLE order by id limit 1 ---- TYPES timestamp,timestamp ---- RESULTS 2009-01-02 01:00:33,2008-12-30 22:59:27 ==== # Add/sub milliseconds (90000033 seconds are 25h33ms), non-function-call like version. select timestamp_col + interval 90000033 milliseconds, interval 90000033 milliseconds + timestamp_col, timestamp_col - interval 90000033 milliseconds from alltypes$TABLE order by id limit 1 ---- TYPES timestamp,timestamp,timestamp ---- RESULTS 2009-01-02 01:00:00.033000000,2009-01-02 01:00:00.033000000,2008-12-30 22:59:59.967000000 ==== # Add/sub milliseconds (90000033 seconds are 25h33ms), function-call like version. select date_add(timestamp_col, interval 90000033 milliseconds), date_sub(timestamp_col, interval 90000033 milliseconds) from alltypes$TABLE order by id limit 1 ---- TYPES timestamp,timestamp ---- RESULTS 2009-01-02 01:00:00.033000000,2008-12-30 22:59:59.967000000 ==== # Add/sub microseconds, non-function-call like version. select timestamp_col + interval 1033 microseconds, interval 1033 microseconds + timestamp_col, timestamp_col - interval 1033 microseconds from alltypes$TABLE order by id limit 1 ---- TYPES timestamp,timestamp,timestamp ---- RESULTS 2009-01-01 00:00:00.001033000,2009-01-01 00:00:00.001033000,2008-12-31 23:59:59.998967000 ==== # Add/sub microseconds, function-call like version. select date_add(timestamp_col, interval 1033 microseconds), date_sub(timestamp_col, interval 1033 microseconds) from alltypes$TABLE order by id limit 1 ---- TYPES timestamp,timestamp ---- RESULTS 2009-01-01 00:00:00.001033000,2008-12-31 23:59:59.998967000 ==== # Add/sub nanoseconds, non-function-call like version. select timestamp_col + interval 1033 nanoseconds, interval 1033 nanoseconds + timestamp_col, timestamp_col - interval 1033 nanoseconds from alltypes$TABLE order by id limit 1 ---- TYPES timestamp,timestamp,timestamp ---- RESULTS 2009-01-01 00:00:00.000001033,2009-01-01 00:00:00.000001033,2008-12-31 23:59:59.999998967 ==== # Add/sub nanoseconds, function-call like version. select date_add(timestamp_col, interval 1033 nanoseconds), date_sub(timestamp_col, interval 1033 nanoseconds) from alltypes$TABLE order by id limit 1 ---- TYPES timestamp,timestamp ---- RESULTS 2009-01-01 00:00:00.000001033,2008-12-31 23:59:59.999998967 ==== # Chaining of arithmetic operations (only non-function-call like version). select timestamp_col + interval 10 years + interval 2 months + interval 5 days, interval 10 years + timestamp_col + interval 2 months + interval 5 days, timestamp_col + interval 10 years - interval 2 months + interval 5 days, interval 10 years + timestamp_col - interval 2 months + interval 5 days, timestamp_col - interval 10 years - interval 2 months - interval 5 days from alltypes$TABLE order by id limit 1 ---- TYPES timestamp,timestamp,timestamp,timestamp,timestamp ---- RESULTS 2019-03-06 00:00:00,2019-03-06 00:00:00,2018-11-06 00:00:00,2018-11-06 00:00:00,1998-10-27 00:00:00 ==== select timestamp_col + interval 10 hours + interval 2 minutes + interval 5 seconds + interval 3 milliseconds + interval 3 microseconds + interval 3 nanoseconds, interval 10 hours + timestamp_col + interval 2 minutes + interval 5 seconds + interval 3 milliseconds + interval 3 microseconds + interval 3 nanoseconds, timestamp_col + interval 10 hours - interval 2 minutes + interval 5 seconds - interval 3 milliseconds + interval 3 microseconds - interval 3 nanoseconds, interval 10 hours + timestamp_col + interval 2 minutes + interval 5 seconds - interval 3 milliseconds + interval 3 microseconds - interval 3 nanoseconds, timestamp_col - interval 10 hours - interval 2 minutes - interval 5 seconds - interval 3 milliseconds - interval 3 microseconds - interval 3 nanoseconds from alltypes$TABLE order by id limit 1 ---- TYPES timestamp,timestamp,timestamp,timestamp,timestamp ---- RESULTS 2009-01-01 10:02:05.003003003,2009-01-01 10:02:05.003003003,2009-01-01 09:58:04.997002997,2009-01-01 10:02:04.997002997,2008-12-31 13:57:54.996996997 ==== # Test corner cases and also timestamp arithmetic without from clause. select cast("2012-02-29 00:00:00" as timestamp) + interval 1 year, cast("2013-02-28 00:00:00" as timestamp) - interval 1 year, cast("2012-01-01 00:00:00" as timestamp) + interval 365 days, cast("2013-01-01 00:00:00" as timestamp) - interval 366 days ---- TYPES timestamp,timestamp,timestamp,timestamp ---- RESULTS 2013-02-28 00:00:00,2012-02-29 00:00:00,2012-12-31 00:00:00,2012-01-01 00:00:00 ==== # Test overflow (2147483647 is MAX_INT). select cast("2012-01-01 00:00:00" as timestamp) + interval 2147483647 years, cast("2012-01-01 00:00:00" as timestamp) - interval 2147483647 years ---- TYPES timestamp,timestamp ---- RESULTS 2011-01-01 00:00:00,2013-01-01 00:00:00 ==== # Timestamp arithmetic inside a predicate. select year, month from alltypes$TABLE where year = year((cast('2012-01-01 09:10:11' as timestamp) - interval 3 years)) and month = month((cast('2012-01-01 09:10:11' as timestamp) + interval 3 months)) limit 3 ---- TYPES int,int ---- RESULTS 2009,4 2009,4 2009,4 ==== # Test NULLs in second operand select count(*) from alltypesagg$TABLE where (cast('2012-01-01 09:10:11' as timestamp) + interval tinyint_col seconds) IS NULL ---- TYPES bigint ---- RESULTS 1000 ==== # Test NULLs in first operand select count(*) from alltypesagg$TABLE where (cast('2012-01-01 09:10:11' as timestamp) + interval tinyint_col seconds) + interval 10 years IS NULL ---- TYPES bigint ---- RESULTS 1000 ====