如何在ClickHouse中使用lambda max(a,b)函数?

时间:2018-11-16 10:03:21

标签: clickhouse

有没有办法使用ClickHouse的lambda,对两个整数执行max函数? 像这样:

SELECT 
    [0,1,2,3,4,5] as five, 
    arrayMap(i -> max(five[i], 3), arrayEnumerate(five)) as X

返回

     five        expected X   
0,1,2,3,4,5     3,3,3,3,4,5

1 个答案:

答案 0 :(得分:2)

不确定我是否理解您的示例(在语法上不正确),但是对于超过两个整数的max,ClickHouse具有函数great(x,y):

SELECT 
  [0, 1, 2, 3, 4, 5] AS five, 
  arrayMap(i -> greatest(i, 3), five) AS X

┌─five──────────┬─X─────────────┐
│ [0,1,2,3,4,5] │ [3,3,3,3,4,5] │
└───────────────┴───────────────┘