Clickhouse-视图中的别名

问题描述 投票:1回答:1

我想在SELECT查询中使用别名创建视图。尝试使用此语法后,将无法使用。Clickhouse在视图查询中不支持别名,或者我的语法不正确?

错误消息:

从服务器收到的异常(版本20.3.5):代码:352。DB :: Exception:从localhost:9000接收。 DB :: Exception:无法检测左右JOIN键。 JOIN ON部分不明确。.

如果我在JOIN中删除别名(打开A.column1 = B.column1 --->打开table_a.column1 = table_b.column1时出现错误消息:

从服务器收到的异常(版本20.3.5):代码:47。DB :: Exception:从localhost:9000接收。 DB :: Exception:缺少列:

创建表:

CREATE TABLE IF NOT EXISTS table_a
(
    `column1` Nullable(Int32),
    `column2` Nullable(Int32),
    `column3` Nullable(Int32),
    `column4` Nullable(Int32)
)
ENGINE = MergeTree()
PARTITION BY tuple()
order by tuple();


CREATE TABLE IF NOT EXISTS table_b
(
    `column1` Nullable(Int32),
    `column2` Nullable(Int32),
    `column3` Nullable(Int32),
    `column4` Nullable(Int32)
)
ENGINE = MergeTree()
PARTITION BY tuple()
order by tuple();

查看查询:

CREATE VIEW IF NOT EXISTS view_table_AB AS 
SELECT
A.column1,
A.column2,
A.column3,
A.column4,

B.column1,
B.column2,
B.column3,
B.column4
FROM table_a AS A
INNER JOIN table_b AS B ON A.column1 = B.column1;

DOC clickhouse:https://clickhouse.tech/docs/fr/sql-reference/syntax/#syntax-expression_aliases

谢谢您的帮助

view clickhouse
1个回答
0
投票

似乎是错误。我添加了CH Issue 11000,让我们等待答案。

因为解决方法需要指定数据库前缀而不是别名:

CREATE VIEW IF NOT EXISTS view_table_AB AS 
SELECT
    table_a.column1,
    table_a.column2,
    table_a.column3,
    table_a.column4,

    table_b.column1,
    table_b.column2,
    table_b.column3,
    table_b.column4
FROM table_a
INNER JOIN table_b ON table_a.column1 = table_b.column1;
© www.soinside.com 2019 - 2024. All rights reserved.