ClickHouse修改表字段

ClickHouse修改表字段

本文中使用的表引擎为:MergeTree

注:部分表引擎,创建后,不可修改表结构。

详情见官网

1.添加字段

之前在添加表字段时,碰到一个坑。

执行SQL:

-- 错误的
alter table event add column '$user_id' Nullable(String);

-- 正确的
alter table event add column `$user_id` Nullable(String);
Code: 62, e.displayText() = DB::Exception: Syntax error: failed at position 34: '$user_id' String AFTER chart_position. Expected one of: IF NOT EXISTS, compound identifier, identifier, column declaration, list of elements (version 20.4.2.9 (official build))

经过排查,发现是因为'符号的问题,在SQL中,因为表字段使用$开头,导致不能直接写。必须要用`这个符号才行。后来改为下面这样才成功执行。

2.修改字段

alter table user modify column user_name Nullable(String);

3.删除字段

alter table user drop column user_name;

猜你喜欢

转载自blog.csdn.net/LitongZero/article/details/106349689