ClickHouse/dbms/tests/queries/0_stateless/00294_shard_enums.sql

81 lines
2.3 KiB
MySQL
Raw Normal View History

2015-12-29 18:40:55 +00:00
set max_threads = 1;
2019-06-07 15:41:24 +00:00
drop table if exists enums;
2015-12-29 15:17:29 +00:00
2019-06-07 15:41:24 +00:00
create table enums (
d Date default '2015-12-29', k default 0,
e Enum8('world' = 2, 'hello' = 1), sign Enum8('minus' = -1, 'plus' = 1),
letter Enum16('a' = 0, 'b' = 1, 'c' = 2, '*' = -256)
2015-12-29 15:17:29 +00:00
) engine = MergeTree(d, k, 1);
2019-06-07 15:41:24 +00:00
desc table enums;
2015-12-29 15:17:29 +00:00
-- insert default values
2019-06-07 15:41:24 +00:00
insert into enums (k) values (0);
select * from enums;
2015-12-29 15:17:29 +00:00
2019-06-07 15:41:24 +00:00
alter table enums modify column e Enum8('world' = 2, 'hello' = 1, '!' = 3);
desc table enums;
2015-12-29 15:17:29 +00:00
2019-06-07 15:41:24 +00:00
insert into enums (e, sign, letter) values ('!', 'plus', 'b');
select * from enums ORDER BY _part;
2015-12-29 15:17:29 +00:00
-- expand `e` and `sign` from Enum8 to Enum16 without changing values, change values of `letter` without changing type
2019-06-07 15:41:24 +00:00
alter table enums
modify column e Enum16('world' = 2, 'hello' = 1, '!' = 3),
modify column sign Enum16('minus' = -1, 'plus' = 1),
modify column letter Enum16('a' = 0, 'b' = 1, 'c' = 2, 'no letter' = -256);
2019-06-07 15:41:24 +00:00
desc table enums;
2015-12-29 15:17:29 +00:00
2019-06-07 15:41:24 +00:00
select * from enums ORDER BY _part;
2015-12-29 15:17:29 +00:00
2019-06-07 15:41:24 +00:00
alter table enums
modify column e Enum8('world' = 2, 'hello' = 1, '!' = 3),
modify column sign Enum8('minus' = -1, 'plus' = 1);
2015-12-29 15:17:29 +00:00
2019-06-07 15:41:24 +00:00
desc table enums;
2015-12-29 15:17:29 +00:00
2019-06-07 15:41:24 +00:00
insert into enums (letter, e) values ('c', 'world');
select * from enums ORDER BY _part;
2015-12-29 15:17:29 +00:00
2019-06-07 15:41:24 +00:00
drop table enums;
2015-12-29 15:17:29 +00:00
2019-06-07 15:41:24 +00:00
create table enums (e Enum8('a' = 0, 'b' = 1, 'c' = 2, 'd' = 3)) engine = TinyLog;
insert into enums values ('d'), ('b'), ('a'), ('c'), ('a'), ('d');
select * from enums;
2015-12-29 15:17:29 +00:00
-- ORDER BY
2019-06-07 15:41:24 +00:00
select * from enums order by e;
select * from enums order by e desc;
2015-12-29 15:17:29 +00:00
-- GROUP BY
2019-06-07 15:41:24 +00:00
select count(), e from enums group by e;
select any(e) from enums;
2015-12-29 15:17:29 +00:00
-- IN
2019-06-07 15:41:24 +00:00
select * from enums where e in ('a', 'd');
select * from enums where e in (select e from enums);
2015-12-29 15:17:29 +00:00
-- DISTINCT
2019-06-07 15:41:24 +00:00
select distinct e from enums;
2015-12-29 15:17:29 +00:00
-- Comparison
2019-06-07 15:41:24 +00:00
select * from enums where e = e;
select * from enums where e = 'a' or e = 'd';
select * from enums where e != 'a';
select *, e < 'b' from enums;
select *, e > 'b' from enums;
2015-12-29 15:17:29 +00:00
-- Conversion
2019-06-07 15:41:24 +00:00
select toInt8(e), toInt16(e), toUInt64(e), toString(e), e from enums;
2015-12-29 15:17:29 +00:00
2019-06-07 15:41:24 +00:00
drop table if exists enums_copy;
create table enums_copy engine = TinyLog as select * from enums;
select * from enums_copy;
2015-12-29 15:17:29 +00:00
2019-06-07 15:41:24 +00:00
drop table enums_copy;
create table enums_copy engine = TinyLog as select * from remote('127.0.0.2', currentDatabase(), enums);
select * from remote('127.0.0.2', currentDatabase(), enums_copy);
2015-12-29 15:17:29 +00:00
2019-06-07 15:41:24 +00:00
drop table enums_copy;
drop table enums;