irpas技术客

clickhouse基本操作_Mr lym_clickhouse基本操作

irpas 5684

1.新增

insert into tableName field1,field2,... values(value1,value2,...);

2.删除

alter table tableName delete where 1=1;

删除一定要带where条件

3.修改

alter table tableName update field1='value' where field1='orgValue'

4.查询

select field1,field2 from tableName where field1=2;

5.新增字段

alter table tableName add column `columnName`? 字段类型;

6.删除字段

alter table tableName drop column `columnName` ;

7.表重命名

rename table A to B

8.修改字段类型(慎用Nullable)

alter table tableName MODIFY COLUMN fieldName?字段类型;

9.创建TTL

? ?已存在表添加TTL

? ?alter table tableName modify TTL create_date + INTERVAL +1 DAY

? ?创建表时增加TTL

? CREATE TABLE example_table (

????????`event_date` Date,

????????`uid` Int32,

????????`name` String

)

ENGINE = ReplicatedAggregatingMergeTree('/clickhouse/tables/{shard}/example_table', '{replica}')

PARTITION BY event_date

ORDER BY uid

TTL event_date + toIntervalMonth(1)

SETTINGS index_granularity = 128;

# 修改表的 TTL,event_date超过三个月的数据自动删除

ALTER TABLE example_table MODIFY TTL event_date + toIntervalMonth(3);

10.删除分区

alter table 表名 drop partition partitionName;

?分区查询:

select * from system.parts p where table = '表名'

11.添加注释

ALTER TABLE tableName COMMENT COLUMN columnName?'注释信息';


1.本站遵循行业规范,任何转载的稿件都会明确标注作者和来源;2.本站的原创文章,会注明原创字样,如未注明都非原创,如有侵权请联系删除!;3.作者投稿可能会经我们编辑修改或补充;4.本站不提供任何储存功能只提供收集或者投稿人的网盘链接。

标签: #clickhouse基本操作 #1新增insert #into #tableName #field1 #field2 #valuesvalue1