在ClickHouse中的特定索引处设置数组值

时间:2020-08-06 16:16:04

标签: clickhouse

是否可以在ClickHouse数据库的现有行中的特定索引处更新数组?像alter table mytable set arr[3]=8

1 个答案:

答案 0 :(得分:1)

applicantid

如果数组索引= 3,则名称='1'

create table xxx(A Int64, Person Nested (Name String, value String))
Engine=MergeTree order by A;

insert into xxx values (1, ['a','b','c'], ['aaa','bbb','ccc'])

如果名称= a,则名称= 1

alter table xxx update "Person.Name" = 
arrayMap( i-> if(i=3,'1',"Person.Name"[i]), arrayEnumerate("Person.Name")) where 1;

select *  from xxx;
┌─A─┬─Person.Name───┬─Person.value────────┐
│ 1 │ ['a','b','1'] │ ['aaa','bbb','ccc'] │
└───┴───────────────┴─────────────────────┘

如果名称= c,则值= 333

alter table xxx update "Person.Name" = 
arrayMap( i-> if(i='a','1',i), "Person.Name") where 1;
    
select  * from xxx;
┌─A─┬─Person.Name───┬─Person.value────────┐
│ 1 │ ['1','b','c'] │ ['aaa','bbb','ccc'] │
└───┴───────────────┴─────────────────────┘