【问题标题】:Clickhouse - Alias in viewClickhouse - 别名在视图中
【发布时间】:2020-09-04 00:03:05
【问题描述】:

我想在 SELECT 查询中创建带有别名的视图。 尝试使用此语法后,它不起作用。 Clickhouse 不支持视图查询中的别名或我的语法不好?

错误信息:

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

如果我在 JOIN 中删除别名(ON A.column1 = B.column1 ---> ON table_a.column1 = table_b.column1),则会出现错误消息:

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

创建表:

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

感谢您的帮助

【问题讨论】:

  • 您能提供更多信息吗?你能发布列的类型和外键约束吗?
  • 我无法在 CH 20.3.8.53 上重现它。试试这个查询:create view if not exists view_01 AS select D.name, D.engine, C.table, C.name, C.type from system.columns AS C inner join system.databases AS D ON C. database = D.name - 对你有用吗?
  • 他没有主键和外键
  • @vladimir 我测试
  • @M46 我用创建表编辑了我的问题

标签: view clickhouse


【解决方案1】:

看起来这是错误。我加了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;

【讨论】:

  • 感谢您的宝贵时间,我们将 Actian 数据库迁移到 clickhouse。我必须修改应用程序的所有请求,因为我们使用别名?
猜你喜欢
  • 2020-06-25
  • 2020-09-20
  • 2021-01-09
  • 1970-01-01
  • 2021-08-14
  • 2018-12-28
  • 2021-12-06
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多