diff --git a/mysql-test/suite/tianmu/r/aliases.result b/mysql-test/suite/tianmu/r/aliases.result new file mode 100644 index 000000000..17ce57c58 --- /dev/null +++ b/mysql-test/suite/tianmu/r/aliases.result @@ -0,0 +1,91 @@ +# +# aliases test case +# +DROP DATABASE IF EXISTS aliases_test; +CREATE DATABASE aliases_test; +USE aliases_test; +CREATE TABLE t1 +( +t1_tinyint TINYINT DEFAULT 0, +t1_int INT DEFAULT NULL, +t1_bigint BIGINT, +t1_decimal DECIMAL(5,2), +t1_text TEXT, +t1_char CHAR(5), +t1_varchar VARCHAR(255) DEFAULT 'hello world!', +t1_datetime DATETIME +)ENGINE=Tianmu; +INSERT INTO t1 VALUES(NULL, NULL, NULL, NULL, '', '', '', NULL); +INSERT INTO t1 VALUES(1, 11, 987654321, 122.32, repeat('z', 20), 'aaa', repeat('a', 20), '1111-11-09 11:11:11'); +INSERT INTO t1 VALUES(0, 12, 887654321, 222.32, repeat('y', 20), 'aaa', repeat('b', 20), '1111-11-11 11:11:12'); +INSERT INTO t1 VALUES(1, -12, -987654321, -122.32, repeat('z', 20), 'bbb', repeat('a', 20), '1111-11-10 11:11:10'); +INSERT INTO t1 VALUES(0, -11, -887654321, -222.32, repeat('x', 20), 'bbb', repeat('b', 20), '1111-11-1 11:11:19'); +SELECT * FROM t1; +t1_tinyint t1_int t1_bigint t1_decimal t1_text t1_char t1_varchar t1_datetime +NULL NULL NULL NULL NULL +1 11 987654321 122.32 zzzzzzzzzzzzzzzzzzzz aaa aaaaaaaaaaaaaaaaaaaa 1111-11-09 11:11:11 +0 12 887654321 222.32 yyyyyyyyyyyyyyyyyyyy aaa bbbbbbbbbbbbbbbbbbbb 1111-11-11 11:11:12 +1 -12 -987654321 -122.32 zzzzzzzzzzzzzzzzzzzz bbb aaaaaaaaaaaaaaaaaaaa 1111-11-10 11:11:10 +0 -11 -887654321 -222.32 xxxxxxxxxxxxxxxxxxxx bbb bbbbbbbbbbbbbbbbbbbb 1111-11-01 11:11:19 +SELECT COUNT(*) AS 'Total Rows' FROM t1; +Total Rows +5 +SELECT SUM(t1_int*t1_int) AS 'Sum of Squares of Integer values' FROM t1; +Sum of Squares of Integer values +530 +SELECT t1_int 'Serial no', t1_text 'Name of the Book', t1_datetime 'Publish Date' FROM t1; +Serial no Name of the Book Publish Date +NULL NULL +11 zzzzzzzzzzzzzzzzzzzz 1111-11-09 11:11:11 +12 yyyyyyyyyyyyyyyyyyyy 1111-11-11 11:11:12 +-12 zzzzzzzzzzzzzzzzzzzz 1111-11-10 11:11:10 +-11 xxxxxxxxxxxxxxxxxxxx 1111-11-01 11:11:19 +SELECT CONCAT(t1_char, t1_text, t1_varchar) 'Concatinating String Columns' FROM t1; +Concatinating String Columns + +aaazzzzzzzzzzzzzzzzzzzzaaaaaaaaaaaaaaaaaaaa +aaayyyyyyyyyyyyyyyyyyyybbbbbbbbbbbbbbbbbbbb +bbbzzzzzzzzzzzzzzzzzzzzaaaaaaaaaaaaaaaaaaaa +bbbxxxxxxxxxxxxxxxxxxxxbbbbbbbbbbbbbbbbbbbb +SELECT t1_tinyint AS 'Boolean value' FROM t1; +Boolean value +NULL +1 +0 +1 +0 +SELECT t1_tinyint 'Tinyint', t1_bigint 'Big Int', t1_decimal 'Decimal', t1_text AS 'Text', t1_varchar AS 'Varchar', t1_datetime AS 'Date' FROM t1 WHERE 'Decimal' >= -300 ORDER BY 'Date'; +Tinyint Big Int Decimal Text Varchar Date +NULL NULL NULL NULL +1 987654321 122.32 zzzzzzzzzzzzzzzzzzzz aaaaaaaaaaaaaaaaaaaa 1111-11-09 11:11:11 +0 887654321 222.32 yyyyyyyyyyyyyyyyyyyy bbbbbbbbbbbbbbbbbbbb 1111-11-11 11:11:12 +1 -987654321 -122.32 zzzzzzzzzzzzzzzzzzzz aaaaaaaaaaaaaaaaaaaa 1111-11-10 11:11:10 +0 -887654321 -222.32 xxxxxxxxxxxxxxxxxxxx bbbbbbbbbbbbbbbbbbbb 1111-11-01 11:11:19 +SELECT COUNT(*) AS 'Total rows' FROM t1 AS table1 , t1 AS table2 WHERE table1.t1_int = table2.t1_int; +Total rows +4 +SELECT table1.t1_tinyint, table2.t1_int FROM t1 AS table1 JOIN t1 AS table2 ON table1.t1_int = table2.t1_int; +t1_tinyint t1_int +1 11 +0 12 +1 -12 +0 -11 +CREATE TABLE t2(col1 INT, col2 TEXT)ENGINE=Tianmu; +INSERT INTO t2 VALUES(1, repeat('s',20)),(2, repeat('o',20)),(3, 'sss'),(4, 'ooo'); +CREATE TABLE t3(col1 INT, col2 DATETIME)ENGINE=Tianmu; +INSERT INTO t3 VALUES(1, '2020-2-2'),(2, '2020-3-3'); +SELECT table1.col1, table1.col2 AS 'Text from table1', table2.col2 AS 'Date from table2' FROM t2 AS table1 JOIN t3 AS table2 ON table1.col1 = table2.col1; +col1 Text from table1 Date from table2 +1 ssssssssssssssssssss 2020-02-02 00:00:00 +2 oooooooooooooooooooo 2020-03-03 00:00:00 +SELECT table1.col1, table1.col2 AS 'Text from table1', table2.col2 AS 'Date from table2' FROM t2 AS table1 LEFT JOIN t3 AS table2 ON table1.col1 = table2.col1; +col1 Text from table1 Date from table2 +1 ssssssssssssssssssss 2020-02-02 00:00:00 +2 oooooooooooooooooooo 2020-03-03 00:00:00 +3 sss NULL +4 ooo NULL +SELECT table1.col1, table1.col2 AS 'Text from table1', table2.col2 AS 'Date from table2' FROM t2 AS table1 RIGHT JOIN t3 AS table2 ON table1.col1 = table2.col1; +col1 Text from table1 Date from table2 +1 ssssssssssssssssssss 2020-02-02 00:00:00 +2 oooooooooooooooooooo 2020-03-03 00:00:00 +DROP DATABASE aliases_test; diff --git a/mysql-test/suite/tianmu/r/issue415.result b/mysql-test/suite/tianmu/r/issue415.result index 249be6857..1fda9d870 100644 --- a/mysql-test/suite/tianmu/r/issue415.result +++ b/mysql-test/suite/tianmu/r/issue415.result @@ -1,3 +1,6 @@ +# +# fix issue415 +# use test; CREATE TABLE `select_base_with_primary_key` ( `pk` bigint(11) NOT NULL AUTO_INCREMENT, diff --git a/mysql-test/suite/tianmu/r/type_timestamp.result b/mysql-test/suite/tianmu/r/type_timestamp.result new file mode 100644 index 000000000..92bd3bc20 --- /dev/null +++ b/mysql-test/suite/tianmu/r/type_timestamp.result @@ -0,0 +1,111 @@ +# +# Test cases for the TIMESTAMP datatype +# +DROP DATABASE IF EXISTS timestamp_test; +set sql_mode='STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION'; +CREATE DATABASE timestamp_test; +USE timestamp_test; +CREATE TABLE ctimestamp (a timestamp); +SET time_zone='-5:00'; +INSERT INTO ctimestamp VALUES ('2019-01-01 01:02:03'), ('2019-05-05 01:01:01'); +SET time_zone='+1:00'; +SELECT a FROM ctimestamp ORDER BY a; +a +2019-01-01 07:02:03 +2019-05-05 07:01:01 +SET time_zone='-2:00'; +SELECT a FROM ctimestamp ORDER BY a; +a +2019-01-01 04:02:03 +2019-05-05 04:01:01 +CREATE TABLE ctimestamp2 (a timestamp DEFAULT 0); +INSERT INTO ctimestamp2 SELECT * FROM ctimestamp; +SELECT a FROM ctimestamp2 ORDER BY a; +a +2019-01-01 04:02:03 +2019-05-05 04:01:01 +CREATE TABLE ctimestamp3 (a timestamp); +INSERT INTO ctimestamp3 VALUES (19940101), (940101), +(19940101010203), (940101010203), ('1994-01-01T01:02:03'); +SELECT a FROM ctimestamp3 ORDER BY a; +a +1994-01-01 00:00:00 +1994-01-01 00:00:00 +1994-01-01 01:02:03 +1994-01-01 01:02:03 +1994-01-01 01:02:03 +DROP DATABASE IF EXISTS timestamp_test; +CREATE DATABASE timestamp_test; +USE timestamp_test; +CREATE TABLE ctimestamp (a timestamp); +SET time_zone='+0:00'; +INSERT INTO ctimestamp VALUES ('2019-01-02 00:02:03'), +('2019-01-02 01:02:03'), ('2019-01-02 10:11:12'); +SET time_zone='+1:00'; +SELECT a, a BETWEEN '2019-01-02 02:00:00' AND '2019-01-02 13:00:00' +FROM ctimestamp ORDER BY a; +a a BETWEEN '2019-01-02 02:00:00' AND '2019-01-02 13:00:00' +2019-01-02 01:02:03 0 +2019-01-02 02:02:03 1 +2019-01-02 11:11:12 1 +INSERT INTO ctimestamp VALUES ('2020-01-03 12:12:12'), +('2020-05-06 12:12:12'), ('2020-10-28 12:12:12'); +SELECT a, DAYNAME(a), DAYOFWEEK(a), DATE_FORMAT(a, '%W %M %Y'), +MONTHNAME(a), DATE(a), YEARWEEK(a), DAYOFYEAR(a), YEAR(a), +a + INTERVAL 1 DAY, TIMESTAMPDIFF(DAY, a, '2020-01-01'), +LAST_DAY(a), TRUNCATE(a, -2), a IN ('2019-01-02 01:02:03', a), +TO_DAYS(a), DAY(a), WEEK(a), WEEKDAY(a), GREATEST(a, '2020-07-01'), +MONTH(a), QUARTER(a), DATE_ADD(a, INTERVAL 1 SECOND) +FROM ctimestamp WHERE a > '2020-01-01' ORDER BY a; +a DAYNAME(a) DAYOFWEEK(a) DATE_FORMAT(a, '%W %M %Y') MONTHNAME(a) DATE(a) YEARWEEK(a) DAYOFYEAR(a) YEAR(a) a + INTERVAL 1 DAY TIMESTAMPDIFF(DAY, a, '2020-01-01') LAST_DAY(a) TRUNCATE(a, -2) a IN ('2019-01-02 01:02:03', a) TO_DAYS(a) DAY(a) WEEK(a) WEEKDAY(a) GREATEST(a, '2020-07-01') MONTH(a) QUARTER(a) DATE_ADD(a, INTERVAL 1 SECOND) +2020-01-03 12:12:12 Friday 6 Friday January 2020 January 2020-01-03 201952 3 2020 2020-01-04 12:12:12 -2 2020-01-31 20200103121200 1 737792 3 0 4 2020-07-01 1 1 2020-01-03 12:12:13 +2020-05-06 12:12:12 Wednesday 4 Wednesday May 2020 May 2020-05-06 202018 127 2020 2020-05-07 12:12:12 -126 2020-05-31 20200506121200 1 737916 6 18 2 2020-07-01 5 2 2020-05-06 12:12:13 +2020-10-28 12:12:12 Wednesday 4 Wednesday October 2020 October 2020-10-28 202043 302 2020 2020-10-29 12:12:12 -301 2020-10-31 20201028121200 1 738091 28 43 2 2020-10-28 12:12:12 10 4 2020-10-28 12:12:13 +SELECT UNIX_TIMESTAMP(a), TIME_TO_SEC(a), CEIL(a), +CAST(LEAST(a, '2019-03-03 00:00:00') AS DATETIME), +ROUND(a), SECOND(a), MINUTE(a), HOUR(a), FLOOR(a) +FROM ctimestamp ORDER BY a; +UNIX_TIMESTAMP(a) TIME_TO_SEC(a) CEIL(a) CAST(LEAST(a, '2019-03-03 00:00:00') AS DATETIME) ROUND(a) SECOND(a) MINUTE(a) HOUR(a) FLOOR(a) +1546387323 3723 20190102010203 2019-01-02 01:02:03 20190102010203 3 2 1 20190102010203 +1546390923 7323 20190102020203 2019-01-02 02:02:03 20190102020203 3 2 2 20190102020203 +1546423872 40272 20190102111112 2019-01-02 11:11:12 20190102111112 12 11 11 20190102111112 +1578049932 43932 20200103121212 2019-03-03 00:00:00 20200103121212 12 12 12 20200103121212 +1588763532 43932 20200506121212 2019-03-03 00:00:00 20200506121212 12 12 12 20200506121212 +1603883532 43932 20201028121212 2019-03-03 00:00:00 20201028121212 12 12 12 20201028121212 +DROP DATABASE IF EXISTS timestamp_test; +CREATE DATABASE timestamp_test; +USE timestamp_test; +CREATE TABLE ctimestamp (a timestamp, b int); +SET time_zone='+0:00'; +INSERT INTO ctimestamp VALUES ('2019-01-03 12:12:12', 1), +('2019-01-04 12:12:12', 2), ('2019-01-03 12:12:12', 4), +('2019-01-03 12:12:12', 2), ('2019-01-04 12:12:12', 1); +SELECT a, b, SUM(b) +FROM ctimestamp; +a b SUM(b) +2019-01-03 12:12:12 1 10 +SELECT a, b, MAX(a) +FROM ctimestamp; +a b MAX(a) +2019-01-03 12:12:12 1 2019-01-04 12:12:12 +DROP DATABASE IF EXISTS timestamp_test; +CREATE DATABASE timestamp_test; +USE timestamp_test; +CREATE TABLE ctimestamp (a int, b timestamp); +INSERT INTO ctimestamp VALUES (1, 20190101), (1, 20200202), +(2, 20190202), (2, 20200202), (2, 20190101); +SELECT b, count(*) FROM ctimestamp GROUP BY b ORDER BY b; +b count(*) +2019-01-01 00:00:00 2 +2019-02-02 00:00:00 1 +2020-02-02 00:00:00 2 +SELECT b, max(a), min(a) FROM ctimestamp GROUP BY b ORDER BY b; +b max(a) min(a) +2019-01-01 00:00:00 2 1 +2019-02-02 00:00:00 2 2 +2020-02-02 00:00:00 2 1 +SELECT a, max(b), min(b) FROM ctimestamp GROUP BY a ORDER BY a; +a max(b) min(b) +1 2020-02-02 00:00:00 2019-01-01 00:00:00 +2 2020-02-02 00:00:00 2019-01-01 00:00:00 +DROP DATABASE timestamp_test; diff --git a/mysql-test/suite/tianmu/t/aliases.test b/mysql-test/suite/tianmu/t/aliases.test new file mode 100644 index 000000000..743086d64 --- /dev/null +++ b/mysql-test/suite/tianmu/t/aliases.test @@ -0,0 +1,54 @@ +--source include/have_tianmu.inc + +--echo # +--echo # aliases test case +--echo # + +--disable_warnings +DROP DATABASE IF EXISTS aliases_test; +--enable_warnings + +CREATE DATABASE aliases_test; +USE aliases_test; + +CREATE TABLE t1 +( + t1_tinyint TINYINT DEFAULT 0, + t1_int INT DEFAULT NULL, + t1_bigint BIGINT, + t1_decimal DECIMAL(5,2), + t1_text TEXT, + t1_char CHAR(5), + t1_varchar VARCHAR(255) DEFAULT 'hello world!', + t1_datetime DATETIME +)ENGINE=Tianmu; +INSERT INTO t1 VALUES(NULL, NULL, NULL, NULL, '', '', '', NULL); +INSERT INTO t1 VALUES(1, 11, 987654321, 122.32, repeat('z', 20), 'aaa', repeat('a', 20), '1111-11-09 11:11:11'); +INSERT INTO t1 VALUES(0, 12, 887654321, 222.32, repeat('y', 20), 'aaa', repeat('b', 20), '1111-11-11 11:11:12'); +INSERT INTO t1 VALUES(1, -12, -987654321, -122.32, repeat('z', 20), 'bbb', repeat('a', 20), '1111-11-10 11:11:10'); +INSERT INTO t1 VALUES(0, -11, -887654321, -222.32, repeat('x', 20), 'bbb', repeat('b', 20), '1111-11-1 11:11:19'); + +SELECT * FROM t1; + +SELECT COUNT(*) AS 'Total Rows' FROM t1; +SELECT SUM(t1_int*t1_int) AS 'Sum of Squares of Integer values' FROM t1; +SELECT t1_int 'Serial no', t1_text 'Name of the Book', t1_datetime 'Publish Date' FROM t1; +SELECT CONCAT(t1_char, t1_text, t1_varchar) 'Concatinating String Columns' FROM t1; +SELECT t1_tinyint AS 'Boolean value' FROM t1; +--disable_warnings +SELECT t1_tinyint 'Tinyint', t1_bigint 'Big Int', t1_decimal 'Decimal', t1_text AS 'Text', t1_varchar AS 'Varchar', t1_datetime AS 'Date' FROM t1 WHERE 'Decimal' >= -300 ORDER BY 'Date'; +SELECT COUNT(*) AS 'Total rows' FROM t1 AS table1 , t1 AS table2 WHERE table1.t1_int = table2.t1_int; +--enable_warnings +SELECT table1.t1_tinyint, table2.t1_int FROM t1 AS table1 JOIN t1 AS table2 ON table1.t1_int = table2.t1_int; + +CREATE TABLE t2(col1 INT, col2 TEXT)ENGINE=Tianmu; +INSERT INTO t2 VALUES(1, repeat('s',20)),(2, repeat('o',20)),(3, 'sss'),(4, 'ooo'); +CREATE TABLE t3(col1 INT, col2 DATETIME)ENGINE=Tianmu; +INSERT INTO t3 VALUES(1, '2020-2-2'),(2, '2020-3-3'); + +SELECT table1.col1, table1.col2 AS 'Text from table1', table2.col2 AS 'Date from table2' FROM t2 AS table1 JOIN t3 AS table2 ON table1.col1 = table2.col1; +SELECT table1.col1, table1.col2 AS 'Text from table1', table2.col2 AS 'Date from table2' FROM t2 AS table1 LEFT JOIN t3 AS table2 ON table1.col1 = table2.col1; +SELECT table1.col1, table1.col2 AS 'Text from table1', table2.col2 AS 'Date from table2' FROM t2 AS table1 RIGHT JOIN t3 AS table2 ON table1.col1 = table2.col1; + +# Clean UP +DROP DATABASE aliases_test; diff --git a/mysql-test/suite/tianmu/t/issue415.test b/mysql-test/suite/tianmu/t/issue415.test index 9114b0123..9b477acaf 100644 --- a/mysql-test/suite/tianmu/t/issue415.test +++ b/mysql-test/suite/tianmu/t/issue415.test @@ -1,3 +1,9 @@ +--source include/have_tianmu.inc + +--echo # +--echo # fix issue415 +--echo # + use test; CREATE TABLE `select_base_with_primary_key` ( `pk` bigint(11) NOT NULL AUTO_INCREMENT, diff --git a/mysql-test/suite/tianmu/t/type_timestamp.test b/mysql-test/suite/tianmu/t/type_timestamp.test new file mode 100644 index 000000000..cff43e755 --- /dev/null +++ b/mysql-test/suite/tianmu/t/type_timestamp.test @@ -0,0 +1,127 @@ +--source include/have_tianmu.inc + +--echo # +--echo # Test cases for the TIMESTAMP datatype +--echo # + +# Test insert/literals/microseconds +--disable_warnings +DROP DATABASE IF EXISTS timestamp_test; +set sql_mode='STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION'; +--enable_warnings + +CREATE DATABASE timestamp_test; +USE timestamp_test; + +## Test the effect of changing timezones on timestamp values +CREATE TABLE ctimestamp (a timestamp); +SET time_zone='-5:00'; +INSERT INTO ctimestamp VALUES ('2019-01-01 01:02:03'), ('2019-05-05 01:01:01'); +SET time_zone='+1:00'; +SELECT a FROM ctimestamp ORDER BY a; +SET time_zone='-2:00'; +SELECT a FROM ctimestamp ORDER BY a; + +## Test insert +CREATE TABLE ctimestamp2 (a timestamp DEFAULT 0); +INSERT INTO ctimestamp2 SELECT * FROM ctimestamp; +SELECT a FROM ctimestamp2 ORDER BY a; + +## Test literals +CREATE TABLE ctimestamp3 (a timestamp); +INSERT INTO ctimestamp3 VALUES (19940101), (940101), +(19940101010203), (940101010203), ('1994-01-01T01:02:03'); +SELECT a FROM ctimestamp3 ORDER BY a; + +## Test microseconds error +#CREATE TABLE ctimestamp4 (a timestamp(6) default 0); +#INSERT INTO ctimestamp4 VALUES (0), ('2019-01-01 01:01:01.123456'); +#SELECT a, microsecond(a) FROM ctimestamp4 ORDER BY a; + +--disable_warnings +DROP DATABASE IF EXISTS timestamp_test; +--enable_warnings + +CREATE DATABASE timestamp_test; +USE timestamp_test; + +CREATE TABLE ctimestamp (a timestamp); +SET time_zone='+0:00'; +INSERT INTO ctimestamp VALUES ('2019-01-02 00:02:03'), +('2019-01-02 01:02:03'), ('2019-01-02 10:11:12'); +SET time_zone='+1:00'; + +SELECT a, a BETWEEN '2019-01-02 02:00:00' AND '2019-01-02 13:00:00' +FROM ctimestamp ORDER BY a; + +#SELECT a, IF(a < '2019-01-02 02:00:00', 'yes', 'no'), +#ADDTIME(a, '1:1:1'), STR_TO_DATE(a, '%Y-%m-%d %H:%i:%s'), +#EXTRACT(DAY_HOUR FROM a), EXTRACT(MINUTE_SECOND FROM a), +#TIME_FORMAT(a, '%H:\%i:\%s'), a RLIKE '02:03', IFNULL(NULL, a), +#CASE a WHEN '2019-01-02 01:02:03' THEN 'found' WHEN '2019-01-02 11:11:12' +#THEN 'found2' ELSE 'notfound' END, CHAR_LENGTH(a), +#CAST(a AS UNSIGNED INT), CAST(a AS CHAR), CAST(a AS DATE), +#TIME(CAST(a AS DATETIME)), TIME(COALESCE(NULL, a)), HEX(a), +#NULLIF(a, '2019-01-02 01:02:03'), TIMEDIFF(a, '2019-01-01 01:02:03') +#FROM ctimestamp ORDER BY a; + +INSERT INTO ctimestamp VALUES ('2020-01-03 12:12:12'), +('2020-05-06 12:12:12'), ('2020-10-28 12:12:12'); + +SELECT a, DAYNAME(a), DAYOFWEEK(a), DATE_FORMAT(a, '%W %M %Y'), +MONTHNAME(a), DATE(a), YEARWEEK(a), DAYOFYEAR(a), YEAR(a), +a + INTERVAL 1 DAY, TIMESTAMPDIFF(DAY, a, '2020-01-01'), +LAST_DAY(a), TRUNCATE(a, -2), a IN ('2019-01-02 01:02:03', a), +TO_DAYS(a), DAY(a), WEEK(a), WEEKDAY(a), GREATEST(a, '2020-07-01'), +MONTH(a), QUARTER(a), DATE_ADD(a, INTERVAL 1 SECOND) +FROM ctimestamp WHERE a > '2020-01-01' ORDER BY a; + +SELECT UNIX_TIMESTAMP(a), TIME_TO_SEC(a), CEIL(a), +CAST(LEAST(a, '2019-03-03 00:00:00') AS DATETIME), +ROUND(a), SECOND(a), MINUTE(a), HOUR(a), FLOOR(a) +FROM ctimestamp ORDER BY a; + +--disable_warnings +DROP DATABASE IF EXISTS timestamp_test; +--enable_warnings + +CREATE DATABASE timestamp_test; +USE timestamp_test; + +CREATE TABLE ctimestamp (a timestamp, b int); +SET time_zone='+0:00'; +INSERT INTO ctimestamp VALUES ('2019-01-03 12:12:12', 1), +('2019-01-04 12:12:12', 2), ('2019-01-03 12:12:12', 4), +('2019-01-03 12:12:12', 2), ('2019-01-04 12:12:12', 1); + +## Test SUM + +SELECT a, b, SUM(b) +FROM ctimestamp; + +## Test MAX + +SELECT a, b, MAX(a) +FROM ctimestamp; + +# Test aggregate functions +--disable_warnings +DROP DATABASE IF EXISTS timestamp_test; +--enable_warnings + +CREATE DATABASE timestamp_test; +USE timestamp_test; + +CREATE TABLE ctimestamp (a int, b timestamp); +INSERT INTO ctimestamp VALUES (1, 20190101), (1, 20200202), +(2, 20190202), (2, 20200202), (2, 20190101); + +# Test count(*) +SELECT b, count(*) FROM ctimestamp GROUP BY b ORDER BY b; + +# Test max/min +SELECT b, max(a), min(a) FROM ctimestamp GROUP BY b ORDER BY b; +SELECT a, max(b), min(b) FROM ctimestamp GROUP BY a ORDER BY a; + +# Cleanup +DROP DATABASE timestamp_test;