ClickHouse/tests/queries/0_stateless/03035_materialized_primary_key.sql
2024-04-10 21:59:14 +05:00

28 lines
603 B
SQL

DROP TABLE IF EXISTS test;
CREATE TABLE test
(
id UInt64,
value String
) ENGINE=MergeTree ORDER BY id;
INSERT INTO test VALUES (1, 'Alice'), (2, 'Bob');
DROP VIEW IF EXISTS test_mv;
CREATE MATERIALIZED VIEW test_mv
(
id UInt64,
value String
) ENGINE=MergeTree
ORDER BY id AS SELECT id, value FROM test;
DROP VIEW IF EXISTS test_mv_pk;
CREATE MATERIALIZED VIEW test_mv_pk
(
value String,
id UInt64
) ENGINE=MergeTree PRIMARY KEY value
POPULATE AS SELECT value, id FROM test;
SELECT name, primary_key
FROM system.tables
WHERE database = currentDatabase() AND name LIKE 'test%';