ClickHouse/tests/queries/0_stateless/01278_alter_rename_combination.sql

56 lines
1.6 KiB
MySQL
Raw Normal View History

2020-05-13 17:43:30 +00:00
DROP TABLE IF EXISTS rename_table;
CREATE TABLE rename_table (key Int32, value1 Int32, value2 Int32) ENGINE = MergeTree ORDER BY tuple();
INSERT INTO rename_table VALUES (1, 2, 3);
-- replace one with other
ALTER TABLE rename_table RENAME COLUMN value1 TO old_value1, RENAME COLUMN value2 TO value1;
SHOW CREATE TABLE rename_table;
SELECT * FROM rename_table FORMAT TSVWithNames;
2020-05-14 16:56:13 +00:00
INSERT INTO rename_table VALUES (4, 5, 6);
-- rename all columns simultaneously
ALTER TABLE rename_table RENAME COLUMN old_value1 TO v1, RENAME COLUMN value1 TO v2, RENAME COLUMN key to k;
SHOW CREATE TABLE rename_table;
SELECT * FROM rename_table ORDER BY k FORMAT TSVWithNames;
2020-05-13 17:43:30 +00:00
DROP TABLE IF EXISTS rename_table;
2020-05-14 16:56:13 +00:00
SELECT '---polymorphic---';
DROP TABLE IF EXISTS rename_table_polymorphic;
CREATE TABLE rename_table_polymorphic (
key Int32,
value1 Int32,
value2 Int32
)
ENGINE = MergeTree
ORDER BY tuple()
SETTINGS min_rows_for_wide_part = 10000;
INSERT INTO rename_table_polymorphic VALUES (1, 2, 3);
ALTER TABLE rename_table_polymorphic RENAME COLUMN value1 TO old_value1, RENAME COLUMN value2 TO value1;
SHOW CREATE TABLE rename_table_polymorphic;
SELECT * FROM rename_table_polymorphic FORMAT TSVWithNames;
2020-05-15 10:26:44 +00:00
INSERT INTO rename_table_polymorphic VALUES (4, 5, 6);
-- rename all columns simultaneously
ALTER TABLE rename_table_polymorphic RENAME COLUMN old_value1 TO v1, RENAME COLUMN value1 TO v2, RENAME COLUMN key to k;
SHOW CREATE TABLE rename_table_polymorphic;
SELECT * FROM rename_table_polymorphic ORDER BY k FORMAT TSVWithNames;
2020-05-14 16:56:13 +00:00
DROP TABLE IF EXISTS rename_table_polymorphic;