Clickhouse: Array arithmetic functions like arrayPlus, arraySub, arrayMulti ?

Created on 19 Sep 2017  Β·  2Comments  Β·  Source: ClickHouse/ClickHouse

Are there array arithmetic functions for arrays, like subtract each element of an array from another array elements?

:) SELECT arraySub([5,6,7], [1,2,3]) as sub
result:
sub
[4,4,4]
question

Most helpful comment

Hi!
You could use lambdas:

SELECT arrayMap((a, b) -> (a - b), [5, 6, 7], [1, 2, 3])

β”Œβ”€arrayMap(lambda(tuple(a, b), minus(a, b)), [5, 6, 7], [1, 2, 3])─┐
β”‚ [4,4,4]                                                          β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

1 rows in set. Elapsed: 0.001 sec. 

All 2 comments

Hi!
You could use lambdas:

SELECT arrayMap((a, b) -> (a - b), [5, 6, 7], [1, 2, 3])

β”Œβ”€arrayMap(lambda(tuple(a, b), minus(a, b)), [5, 6, 7], [1, 2, 3])─┐
β”‚ [4,4,4]                                                          β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

1 rows in set. Elapsed: 0.001 sec. 

More details about higher-order functions: https://clickhouse.yandex/docs/en/single/#higher-order-functions

Was this page helpful?
0 / 5 - 0 ratings